Add minimal loading script with 'val' split
Browse files- dataset.py +43 -0
dataset.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dataset.py
|
| 2 |
+
import os, glob, datasets
|
| 3 |
+
from datasets import SplitGenerator
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class ITTO(datasets.GeneratorBasedBuilder):
|
| 7 |
+
VERSION = datasets.Version("1.0.0")
|
| 8 |
+
|
| 9 |
+
def _info(self):
|
| 10 |
+
return datasets.DatasetInfo(
|
| 11 |
+
features=datasets.Features(
|
| 12 |
+
{
|
| 13 |
+
"image": datasets.Image(),
|
| 14 |
+
"label": datasets.Value("string"),
|
| 15 |
+
}
|
| 16 |
+
)
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def _split_generators(self, dl_manager):
|
| 20 |
+
# Name the split exactly how you want it shown:
|
| 21 |
+
return [
|
| 22 |
+
SplitGenerator(
|
| 23 |
+
name="val", gen_kwargs={"data_dir": self.config.data_dir or ""}
|
| 24 |
+
)
|
| 25 |
+
]
|
| 26 |
+
# Or: name=datasets.Split.VALIDATION
|
| 27 |
+
|
| 28 |
+
def _generate_examples(self, data_dir):
|
| 29 |
+
# Example: scan local folders when a user supplies data_dir
|
| 30 |
+
roots = ["ego4d/frames", "lvos/frames", "mose/frames"]
|
| 31 |
+
eid = 0
|
| 32 |
+
for root in roots:
|
| 33 |
+
root_path = os.path.join(data_dir, root)
|
| 34 |
+
if not os.path.isdir(root_path):
|
| 35 |
+
continue
|
| 36 |
+
for cls in sorted(os.listdir(root_path)):
|
| 37 |
+
cls_dir = os.path.join(root_path, cls)
|
| 38 |
+
if not os.path.isdir(cls_dir):
|
| 39 |
+
continue
|
| 40 |
+
for fp in glob.glob(os.path.join(cls_dir, "*")):
|
| 41 |
+
if os.path.isfile(fp):
|
| 42 |
+
yield eid, {"image": fp, "label": cls}
|
| 43 |
+
eid += 1
|