iamirulofficial commited on
Commit
4ca7b0a
·
verified ·
1 Parent(s): fb243e8

Delete loading script auxiliary file

Browse files
Files changed (1) hide show
  1. image_dataset.py +0 -95
image_dataset.py DELETED
@@ -1,95 +0,0 @@
1
- import os
2
- import json
3
- import random
4
- from datasets import (
5
- BuilderConfig,
6
- DatasetInfo,
7
- DownloadManager,
8
- GeneratorBasedBuilder,
9
- SplitGenerator,
10
- Split,
11
- Features,
12
- Image,
13
- Sequence,
14
- Value,
15
- )
16
-
17
- class ImageSubsetConfig(BuilderConfig):
18
- """BuilderConfig for small vs. full dataset."""
19
- def __init__(self, name, sample_size=None, **kwargs):
20
- super().__init__(
21
- name=name,
22
- version="1.0.0",
23
- description=kwargs.get("description", "")
24
- )
25
- self.sample_size = sample_size
26
-
27
- class MyImageDataset(GeneratorBasedBuilder):
28
- """A dataset of images with actuated_angle from metadata.json."""
29
- BUILDER_CONFIGS = [
30
- ImageSubsetConfig(
31
- name="full",
32
- sample_size=None,
33
- description="All images (≈100 GB). Use with streaming=True."
34
- ),
35
- ImageSubsetConfig(
36
- name="small",
37
- sample_size=2,
38
- description="Random subset of 10 000 images for quick iteration."
39
- ),
40
- ]
41
- DEFAULT_CONFIG_NAME = "smgit all"
42
-
43
- def _info(self):
44
- return DatasetInfo(
45
- description="Images with a 2-D actuated_angle from metadata.json",
46
- features=Features({
47
- "image": Image(), # the image file
48
- "actuated_angle": Sequence(Value("int32")), # [angle0, angle1]
49
- }),
50
- supervised_keys=None,
51
- )
52
-
53
- def _split_generators(self, dl_manager: DownloadManager):
54
- data_dir = dl_manager.manual_dir or os.path.abspath(os.path.dirname(__file__))
55
- images_dir = os.path.join(data_dir, "images")
56
- meta_path = os.path.join(data_dir, "metadata.json")
57
-
58
- # load your filename → {"0":…, "1":…} mapping
59
- with open(meta_path, "r", encoding="utf-8") as f:
60
- metadata = json.load(f)
61
-
62
- # sample if in "small" config
63
- if self.config.sample_size:
64
- all_fnames = list(metadata.keys())
65
- random.seed(42)
66
- selected = set(random.sample(all_fnames, self.config.sample_size))
67
- else:
68
- selected = set(metadata.keys())
69
-
70
- return [
71
- SplitGenerator(
72
- name=Split.TRAIN,
73
- gen_kwargs={
74
- "images_dir": images_dir,
75
- "metadata": metadata,
76
- "selected": selected,
77
- },
78
- ),
79
- ]
80
-
81
- def _generate_examples(self, images_dir, metadata, selected):
82
- """Yields examples of the form { "image": path, "actuated_angle": [int, int] }"""
83
- for idx, fname in enumerate(selected):
84
- if fname not in metadata:
85
- continue
86
- image_path = os.path.join(images_dir, fname)
87
- if not os.path.exists(image_path):
88
- continue
89
- meta = metadata[fname]
90
- # extract the two angle values (keys "0" and "1")
91
- angles = [ int(meta.get("0", 0)), int(meta.get("1", 0)) ]
92
- yield idx, {
93
- "image": image_path,
94
- "actuated_angle": angles,
95
- }