File size: 9,374 Bytes
88e3654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd2971d
88e3654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# """EMT dataset."""

# import os
# import json

# import datasets


# _HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"

# _LICENSE = "CC-BY-SA 4.0"

# _CITATION = """  
# @article{EMTdataset2025,  
#       title={EMT: A Visual Multi-Task Benchmark Dataset for Autonomous Driving in the Arab Gulf Region},  
#       author={Nadya Abdel Madjid and Murad Mebrahtu and Abdelmoamen Nasser and Bilal Hassan and Naoufel Werghi and Jorge Dias and Majid Khonji},  
#       year={2025},  
#       eprint={2502.19260},  
#       archivePrefix={arXiv},  
#       primaryClass={cs.CV},  
#       url={https://arxiv.org/abs/2502.19260}  
# }  
# """ 

# _DESCRIPTION = """\
# A multi-task dataset for detection, tracking, prediction, and intention prediction. 
# This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection + tracking.",
    
# """


# _LABEL_MAP = [
#     'n01440764',
#     'n02102040',
#     'n02979186',
#     'n03000684',
#     'n03028079',
#     'n03394916',
#     'n03417042',
#     'n03425413',
#     'n03445777',
#     'n03888257',
# ]

# # _REPO = "https://huggingface.co/datasets/frgfm/imagenette/resolve/main/metadata"
# _REPO = "https://huggingface.co/datasets/Murdism/EMT/resolve/main/labels"



# class EMTConfig(datasets.BuilderConfig):
#     """BuilderConfig for EMT."""

#     def __init__(self, data_url, metadata_urls, **kwargs):
#         """BuilderConfig for EMT.
#         Args:
#           data_url: `string`, url to download the zip file from.
#           matadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
#           **kwargs: keyword arguments forwarded to super.
#         """
#         super(EMTConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
#         self.data_url = data_url
#         self.metadata_urls = metadata_urls


# class EMT(datasets.GeneratorBasedBuilder):
#     """Imagenette dataset."""

#     BUILDER_CONFIGS = [
#         EMTConfig(
#             name="full_size",
#             description="All images are in their original size.",
#             data_url="https://huggingface.co/datasets/KuAvLab/EMT/blob/main/emt_images.tar.gz",
#             metadata_urls={
#                 "train": f"{_REPO}/train/",
#                 "test": f"{_REPO}/test/",
#             },
#         )
#     ]

#     def _info(self):
#         return datasets.DatasetInfo(
#             description=_DESCRIPTION + self.config.description,
#             features=datasets.Features(
#                 {
#                     "image": datasets.Image(),
#                     "label": datasets.ClassLabel(
#                         names=[
#                             "bbox",
#                             "class_id",
#                             "track_id",
#                             "class_name",
  
#                         ]
#                     ),
#                 }
#             ),
#             supervised_keys=None,
#             homepage=_HOMEPAGE,
#             license=_LICENSE,
#             citation=_CITATION,
#         )

#     def _split_generators(self, dl_manager):
#         archive_path = dl_manager.download(self.config.data_url)
#         metadata_paths = dl_manager.download(self.config.metadata_urls)
#         archive_iter = dl_manager.iter_archive(archive_path)
#         return [
#             datasets.SplitGenerator(
#                 name=datasets.Split.TRAIN,
#                 gen_kwargs={
#                     "images": archive_iter,
#                     "metadata_path": metadata_paths["train"],
#                 },
#             ),
#             datasets.SplitGenerator(
#                 name=datasets.Split.TEST,
#                 gen_kwargs={
#                     "images": os.path.join(self.config.data_url, "test"),
#                     "metadata_path": metadata_paths["test"],
#                 },
#             ),
#         ]

#     def _generate_examples(self, images, metadata_path):
#         with open(metadata_path, encoding="utf-8") as f:
#             files_to_keep = set(f.read().split("\n"))
#         idx = 0
#         for file_path, file_obj in images:
#             if file_path in files_to_keep:
#                 label = _LABEL_MAP.index(file_path.split("/")[-2])
#                 yield idx, {
#                     "image": {"path": file_path, "bytes": file_obj.read()},
#                     "label": label,
#                 }
#                 idx += 1

"""EMT dataset."""

import os
import json
import pandas as pd
import datasets

_HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"
_LICENSE = "CC-BY-SA 4.0"

_CITATION = """  
@article{EMTdataset2025,  
      title={EMT: A Visual Multi-Task Benchmark Dataset for Autonomous Driving in the Arab Gulf Region},  
      author={Nadya Abdel Madjid and Murad Mebrahtu and Abdelmoamen Nasser and Bilal Hassan and Naoufel Werghi and Jorge Dias and Majid Khonji},  
      year={2025},  
      eprint={2502.19260},  
      archivePrefix={arXiv},  
      primaryClass={cs.CV},  
      url={https://arxiv.org/abs/2502.19260}  
}  
""" 

_DESCRIPTION = """\
A multi-task dataset for detection, tracking, prediction, and intention prediction. 
This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection + tracking.",
"""

_REPO = "https://huggingface.co/datasets/Murdism/EMT/resolve/main/annotations"

class EMTConfig(datasets.BuilderConfig):
    """BuilderConfig for EMT."""

    def __init__(self, data_url, annotation_url, **kwargs):
        """BuilderConfig for EMT.
        Args:
          data_url: `string`, URL to download the image archive (.tar file).
          annotation_url: `string`, URL to download the annotations (Parquet file).
          **kwargs: keyword arguments forwarded to super.
        """
        super(EMTConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
        self.data_url = data_url
        self.annotation_url = annotation_url


class EMT(datasets.GeneratorBasedBuilder):
    """EMT dataset."""

    BUILDER_CONFIGS = [
        EMTConfig(
            name="full_size",
            description="All images are in their original size.",
            data_url="https://huggingface.co/datasets/KuAvLab/EMT/blob/main/emt_images.tar.gz",
            annotation_url="https://huggingface.co/datasets/Murdism/EMT/resolve/main/annotations/",
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION + self.config.description,
            features=datasets.Features(
                {
                    "image": datasets.Image(),
                    "objects": datasets.Sequence(
                        {
                            "bbox": datasets.Sequence(datasets.Float32()),
                            "class_id": datasets.Value("int32"),
                            "track_id": datasets.Value("int32"),
                            "class_name": datasets.Value("string"),
                        }
                    ),
                }
            ),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        archive_path = dl_manager.download(self.config.data_url)
        annotation_paths = {
            "train": dl_manager.download_and_extract(self.config.annotation_url + "train_annotations.parquet"),
            "test": dl_manager.download_and_extract(self.config.annotation_url + "test_annotations.parquet"),
        }
        
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "images": dl_manager.iter_archive(archive_path),
                    "annotation_path": annotation_paths["train"],
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "images": dl_manager.iter_archive(archive_path),
                    "annotation_path": annotation_paths["test"],
                },
            ),
        ]

    def _generate_examples(self, images, annotation_path):
        """Generate examples from Parquet annotations and image archive."""
        
        # Load annotations from Parquet
        df = pd.read_parquet(annotation_path)

        # Convert DataFrame into a dictionary for faster lookups
        annotation_dict = {}
        for _, row in df.iterrows():
            img_path = row["file_path"].split("/")[-2] + "/" + row["file_path"].split("/")[-1]
            print("img_path: ",img_path)
            if img_path not in annotation_dict:
                annotation_dict[img_path] = []
            annotation_dict[img_path].append(
                {
                    "bbox": row["bbox"],
                    "class_id": row["class_id"],
                    "track_id": row["track_id"],
                    "class_name": row["class_name"],
                }
            )

        idx = 0
        for file_path, file_obj in images:
            if file_path in annotation_dict:
                yield idx, {
                    "image": {"path": file_path, "bytes": file_obj.read()},
                    "objects": annotation_dict[file_path],
                }
                idx += 1