File size: 1,449 Bytes
96493af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# dataset.py
import os, glob, datasets
from datasets import SplitGenerator


class ITTO(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    def _info(self):
        return datasets.DatasetInfo(
            features=datasets.Features(
                {
                    "image": datasets.Image(),
                    "label": datasets.Value("string"),
                }
            )
        )

    def _split_generators(self, dl_manager):
        # Name the split exactly how you want it shown:
        return [
            SplitGenerator(
                name="val", gen_kwargs={"data_dir": self.config.data_dir or ""}
            )
        ]
        # Or: name=datasets.Split.VALIDATION

    def _generate_examples(self, data_dir):
        # Example: scan local folders when a user supplies data_dir
        roots = ["ego4d/frames", "lvos/frames", "mose/frames"]
        eid = 0
        for root in roots:
            root_path = os.path.join(data_dir, root)
            if not os.path.isdir(root_path):
                continue
            for cls in sorted(os.listdir(root_path)):
                cls_dir = os.path.join(root_path, cls)
                if not os.path.isdir(cls_dir):
                    continue
                for fp in glob.glob(os.path.join(cls_dir, "*")):
                    if os.path.isfile(fp):
                        yield eid, {"image": fp, "label": cls}
                        eid += 1