Murad Mebrahtu commited on
Commit
2f6e05a
·
1 Parent(s): 73e3647
Files changed (1) hide show
  1. emt.py +39 -190
emt.py CHANGED
@@ -1,144 +1,6 @@
1
- # """EMT dataset."""
2
-
3
- # import os
4
- # import json
5
-
6
- # import datasets
7
-
8
-
9
- # _HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"
10
-
11
- # _LICENSE = "CC-BY-SA 4.0"
12
-
13
- # _CITATION = """
14
- # @article{EMTdataset2025,
15
- # title={EMT: A Visual Multi-Task Benchmark Dataset for Autonomous Driving in the Arab Gulf Region},
16
- # author={Nadya Abdel Madjid and Murad Mebrahtu and Abdelmoamen Nasser and Bilal Hassan and Naoufel Werghi and Jorge Dias and Majid Khonji},
17
- # year={2025},
18
- # eprint={2502.19260},
19
- # archivePrefix={arXiv},
20
- # primaryClass={cs.CV},
21
- # url={https://arxiv.org/abs/2502.19260}
22
- # }
23
- # """
24
-
25
- # _DESCRIPTION = """\
26
- # A multi-task dataset for detection, tracking, prediction, and intention prediction.
27
- # This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection + tracking.",
28
-
29
- # """
30
-
31
-
32
- # _LABEL_MAP = [
33
- # 'n01440764',
34
- # 'n02102040',
35
- # 'n02979186',
36
- # 'n03000684',
37
- # 'n03028079',
38
- # 'n03394916',
39
- # 'n03417042',
40
- # 'n03425413',
41
- # 'n03445777',
42
- # 'n03888257',
43
- # ]
44
-
45
- # # _REPO = "https://huggingface.co/datasets/frgfm/imagenette/resolve/main/metadata"
46
- # _REPO = "https://huggingface.co/datasets/Murdism/EMT/resolve/main/labels"
47
-
48
-
49
-
50
- # class EMTConfig(datasets.BuilderConfig):
51
- # """BuilderConfig for EMT."""
52
-
53
- # def __init__(self, data_url, metadata_urls, **kwargs):
54
- # """BuilderConfig for EMT.
55
- # Args:
56
- # data_url: `string`, url to download the zip file from.
57
- # matadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
58
- # **kwargs: keyword arguments forwarded to super.
59
- # """
60
- # super(EMTConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
61
- # self.data_url = data_url
62
- # self.metadata_urls = metadata_urls
63
-
64
-
65
- # class EMT(datasets.GeneratorBasedBuilder):
66
- # """Imagenette dataset."""
67
-
68
- # BUILDER_CONFIGS = [
69
- # EMTConfig(
70
- # name="full_size",
71
- # description="All images are in their original size.",
72
- # data_url="https://huggingface.co/datasets/KuAvLab/EMT/blob/main/emt_images.tar.gz",
73
- # metadata_urls={
74
- # "train": f"{_REPO}/train/",
75
- # "test": f"{_REPO}/test/",
76
- # },
77
- # )
78
- # ]
79
-
80
- # def _info(self):
81
- # return datasets.DatasetInfo(
82
- # description=_DESCRIPTION + self.config.description,
83
- # features=datasets.Features(
84
- # {
85
- # "image": datasets.Image(),
86
- # "label": datasets.ClassLabel(
87
- # names=[
88
- # "bbox",
89
- # "class_id",
90
- # "track_id",
91
- # "class_name",
92
-
93
- # ]
94
- # ),
95
- # }
96
- # ),
97
- # supervised_keys=None,
98
- # homepage=_HOMEPAGE,
99
- # license=_LICENSE,
100
- # citation=_CITATION,
101
- # )
102
-
103
- # def _split_generators(self, dl_manager):
104
- # archive_path = dl_manager.download(self.config.data_url)
105
- # metadata_paths = dl_manager.download(self.config.metadata_urls)
106
- # archive_iter = dl_manager.iter_archive(archive_path)
107
- # return [
108
- # datasets.SplitGenerator(
109
- # name=datasets.Split.TRAIN,
110
- # gen_kwargs={
111
- # "images": archive_iter,
112
- # "metadata_path": metadata_paths["train"],
113
- # },
114
- # ),
115
- # datasets.SplitGenerator(
116
- # name=datasets.Split.TEST,
117
- # gen_kwargs={
118
- # "images": os.path.join(self.config.data_url, "test"),
119
- # "metadata_path": metadata_paths["test"],
120
- # },
121
- # ),
122
- # ]
123
-
124
- # def _generate_examples(self, images, metadata_path):
125
- # with open(metadata_path, encoding="utf-8") as f:
126
- # files_to_keep = set(f.read().split("\n"))
127
- # idx = 0
128
- # for file_path, file_obj in images:
129
- # if file_path in files_to_keep:
130
- # label = _LABEL_MAP.index(file_path.split("/")[-2])
131
- # yield idx, {
132
- # "image": {"path": file_path, "bytes": file_obj.read()},
133
- # "label": label,
134
- # }
135
- # idx += 1
136
-
137
  """EMT dataset."""
138
 
139
  import os
140
- import json
141
- import pandas as pd
142
  import datasets
143
 
144
  _HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"
@@ -158,41 +20,22 @@ _CITATION = """
158
 
159
  _DESCRIPTION = """\
160
  A multi-task dataset for detection, tracking, prediction, and intention prediction.
161
- This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection + tracking.",
162
  """
163
 
164
- _REPO = "https://huggingface.co/datasets/Murdism/EMT/resolve/main/annotations"
165
-
166
- class EMTConfig(datasets.BuilderConfig):
167
- """BuilderConfig for EMT."""
168
 
169
- def __init__(self, data_url, annotation_url, **kwargs):
170
- """BuilderConfig for EMT.
171
- Args:
172
- data_url: `string`, URL to download the image archive (.tar file).
173
- annotation_url: `string`, URL to download the annotations (Parquet file).
174
- **kwargs: keyword arguments forwarded to super.
175
- """
176
- super(EMTConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
177
- self.data_url = data_url
178
- self.annotation_url = annotation_url
179
 
180
 
181
  class EMT(datasets.GeneratorBasedBuilder):
182
  """EMT dataset."""
183
 
184
- BUILDER_CONFIGS = [
185
- EMTConfig(
186
- name="full_size",
187
- description="All images are in their original size.",
188
- data_url="https://huggingface.co/datasets/KuAvLab/EMT/blob/main/emt_images.tar.gz",
189
- annotation_url="https://huggingface.co/datasets/Murdism/EMT/resolve/main/annotations/",
190
- )
191
- ]
192
-
193
  def _info(self):
194
  return datasets.DatasetInfo(
195
- description=_DESCRIPTION + self.config.description,
196
  features=datasets.Features(
197
  {
198
  "image": datasets.Image(),
@@ -213,12 +56,12 @@ class EMT(datasets.GeneratorBasedBuilder):
213
  )
214
 
215
  def _split_generators(self, dl_manager):
216
- archive_path = dl_manager.download(self.config.data_url)
217
  annotation_paths = {
218
- "train": dl_manager.download_and_extract(self.config.annotation_url + "train_annotations.parquet"),
219
- "test": dl_manager.download_and_extract(self.config.annotation_url + "test_annotations.parquet"),
220
  }
221
-
222
  return [
223
  datasets.SplitGenerator(
224
  name=datasets.Split.TRAIN,
@@ -237,32 +80,38 @@ class EMT(datasets.GeneratorBasedBuilder):
237
  ]
238
 
239
  def _generate_examples(self, images, annotation_path):
240
- """Generate examples from Parquet annotations and image archive."""
241
-
242
- # Load annotations from Parquet
243
- df = pd.read_parquet(annotation_path)
244
-
245
- # Convert DataFrame into a dictionary for faster lookups
246
- annotation_dict = {}
247
- for _, row in df.iterrows():
248
- img_path = row["file_path"].split("/")[-2] + "/" + row["file_path"].split("/")[-1]
249
- print("img_path: ",img_path)
250
- if img_path not in annotation_dict:
251
- annotation_dict[img_path] = []
252
- annotation_dict[img_path].append(
253
- {
254
- "bbox": row["bbox"],
255
- "class_id": row["class_id"],
256
- "track_id": row["track_id"],
257
- "class_name": row["class_name"],
258
- }
259
- )
260
-
 
 
 
 
 
261
  idx = 0
262
  for file_path, file_obj in images:
263
- if file_path in annotation_dict:
 
264
  yield idx, {
265
  "image": {"path": file_path, "bytes": file_obj.read()},
266
- "objects": annotation_dict[file_path],
267
  }
268
  idx += 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  """EMT dataset."""
2
 
3
  import os
 
 
4
  import datasets
5
 
6
  _HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"
 
20
 
21
  _DESCRIPTION = """\
22
  A multi-task dataset for detection, tracking, prediction, and intention prediction.
23
+ This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection + tracking.
24
  """
25
 
26
+ # Image archive URL
27
+ _IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/blob/main/emt_images.tar.gz"
 
 
28
 
29
+ # Annotations URL (organized in train/test subfolders)
30
+ _ANNOTATION_REPO = "https://huggingface.co/datasets/Murdism/EMT/resolve/main/annotations"
 
 
 
 
 
 
 
 
31
 
32
 
33
  class EMT(datasets.GeneratorBasedBuilder):
34
  """EMT dataset."""
35
 
 
 
 
 
 
 
 
 
 
36
  def _info(self):
37
  return datasets.DatasetInfo(
38
+ description=_DESCRIPTION,
39
  features=datasets.Features(
40
  {
41
  "image": datasets.Image(),
 
56
  )
57
 
58
  def _split_generators(self, dl_manager):
59
+ archive_path = dl_manager.download(_IMAGE_ARCHIVE_URL)
60
  annotation_paths = {
61
+ "train": dl_manager.download_and_extract(f"{_ANNOTATION_REPO}/train/"),
62
+ "test": dl_manager.download_and_extract(f"{_ANNOTATION_REPO}/test/"),
63
  }
64
+
65
  return [
66
  datasets.SplitGenerator(
67
  name=datasets.Split.TRAIN,
 
80
  ]
81
 
82
  def _generate_examples(self, images, annotation_path):
83
+ """Generate examples from annotations and image archive."""
84
+
85
+ # Load annotation files
86
+ annotations = {}
87
+ for root, _, files in os.walk(annotation_path):
88
+ for file in files:
89
+ with open(os.path.join(root, file), "r", encoding="utf-8") as f:
90
+ for line in f:
91
+ parts = line.strip().split()
92
+ frame_id, track_id, class_name = parts[:3]
93
+ bbox = list(map(float, parts[4:8])) # Extract bounding box
94
+ class_id = hash(class_name) % 1000 # Convert class_name to numeric ID
95
+
96
+ img_path = f"{frame_id}.jpg"
97
+ if img_path not in annotations:
98
+ annotations[img_path] = []
99
+ annotations[img_path].append(
100
+ {
101
+ "bbox": bbox,
102
+ "class_id": class_id,
103
+ "track_id": int(track_id),
104
+ "class_name": class_name,
105
+ }
106
+ )
107
+
108
+ # Yield dataset entries
109
  idx = 0
110
  for file_path, file_obj in images:
111
+ img_name = os.path.basename(file_path)
112
+ if img_name in annotations:
113
  yield idx, {
114
  "image": {"path": file_path, "bytes": file_obj.read()},
115
+ "objects": annotations[img_name],
116
  }
117
  idx += 1