Upload 2 files
Browse files- dataset.py +34 -0
- organcmnist.npz +3 -0
dataset.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
import datasets
|
| 4 |
+
|
| 5 |
+
class OrganMNIST(datasets.GeneratorBasedBuilder):
|
| 6 |
+
VERSION = datasets.Version("1.0.0")
|
| 7 |
+
|
| 8 |
+
def _info(self):
|
| 9 |
+
return datasets.DatasetInfo(
|
| 10 |
+
description="OrganMNIST dataset from MedMNIST collection",
|
| 11 |
+
features=datasets.Features(
|
| 12 |
+
{
|
| 13 |
+
"image": datasets.Array3D(dtype="uint8", shape=(28, 28, 3)),
|
| 14 |
+
"label": datasets.ClassLabel(num_classes=11),
|
| 15 |
+
}
|
| 16 |
+
),
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def _split_generators(self, dl_manager):
|
| 20 |
+
data_dir = dl_manager.manual_dir
|
| 21 |
+
npz_path = os.path.join(data_dir, "organcmnist.npz")
|
| 22 |
+
return [
|
| 23 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"npz_path": npz_path, "split": "train"}),
|
| 24 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"npz_path": npz_path, "split": "val"}),
|
| 25 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"npz_path": npz_path, "split": "test"}),
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
def _generate_examples(self, npz_path, split):
|
| 29 |
+
data = np.load(npz_path)
|
| 30 |
+
images = data[f"{split}_images.npy"]
|
| 31 |
+
labels = data[f"{split}_labels.npy"].squeeze()
|
| 32 |
+
|
| 33 |
+
for idx in range(len(images)):
|
| 34 |
+
yield idx, {"image": images[idx], "label": int(labels[idx])}
|
organcmnist.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:69cd6d6b6343adc25f916c1c6e2fc786e82443670e25d5da275b1c4e32e8da7a
|
| 3 |
+
size 15526411
|