-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b20a11
commit 71cb40f
Showing
17 changed files
with
86 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
data/ | ||
models/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.POHNY: train | ||
train: | ||
mkdir -p models data | ||
python3 cifar/train.py | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import io | ||
import pickle | ||
import typing as t | ||
from pathlib import Path | ||
|
||
from PIL import Image as PILImage | ||
|
||
from starwhale.api.dataset import Image, MIMEType, BuildExecutor | ||
|
||
ROOT_DIR = Path(__file__).parent.parent / "data" / "cifar-10-batches-py" | ||
TRAIN_DATASET_PATHS = [ROOT_DIR / f"data_batch_{i}" for i in range(1, 6)] | ||
TEST_DATASET_PATHS = [ROOT_DIR / "test_batch"] | ||
|
||
|
||
def parse_meta() -> t.Dict[str, t.Any]: | ||
with (ROOT_DIR / "batches.meta").open("rb") as f: | ||
return pickle.load(f) | ||
|
||
|
||
dataset_meta = parse_meta() | ||
|
||
|
||
def _iter_item(paths: t.List[Path]) -> t.Generator[t.Tuple[t.Any, t.Dict], None, None]: | ||
for path in paths: | ||
with path.open("rb") as f: | ||
content = pickle.load(f, encoding="bytes") | ||
for data, label, filename in zip( | ||
content[b"data"], content[b"labels"], content[b"filenames"] | ||
): | ||
annotations = { | ||
"label": label, | ||
"label_display_name": dataset_meta["label_names"][label], | ||
} | ||
|
||
image_array = data.reshape(3, 32, 32).transpose(1, 2, 0) | ||
image_bytes = io.BytesIO() | ||
PILImage.fromarray(image_array).save(image_bytes, format="PNG") | ||
|
||
yield Image( | ||
fp=image_bytes.getvalue(), | ||
display_name=filename.decode(), | ||
shape=image_array.shape, | ||
mime_type=MIMEType.PNG, | ||
), annotations | ||
|
||
|
||
class CIFAR10TrainBuildExecutor(BuildExecutor): | ||
def iter_item(self) -> t.Generator[t.Tuple[t.Any, t.Any], None, None]: | ||
return _iter_item(TRAIN_DATASET_PATHS) | ||
|
||
|
||
class CIFAR10TestBuildExecutor(BuildExecutor): | ||
def iter_item(self) -> t.Generator[t.Tuple[t.Any, t.Any], None, None]: | ||
return _iter_item(TEST_DATASET_PATHS) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
name: cifar10 | ||
|
||
process: code.data_slicer:CIFAR10Slicer | ||
pip_req: requirements.txt | ||
#name: cifar10-train | ||
#process: cifar.dataset:CIFAR10TrainBuildExecutor | ||
|
||
name: cifar10-test | ||
process: cifar.dataset:CIFAR10TestBuildExecutor | ||
desc: CIFAR10 data and label test dataset | ||
tag: | ||
- bin | ||
|
||
attr: | ||
alignment_size: 4k | ||
volume_size: 2M | ||
volume_size: 10M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
version: 1.0 | ||
name: cifar_net | ||
|
||
model: | ||
- models/cifar_net.pth | ||
|
||
config: | ||
- config/hyperparam.json | ||
|
||
run: | ||
ppl: code.ppl:CIFAR10Inference | ||
ppl: cifar.ppl:CIFAR10Inference | ||
|
||
desc: cifar10 by pytorch | ||
|
||
tag: | ||
- multi_classification |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.