File size: 16,881 Bytes
cdb0b4e fcc30c7 88e3654 63c9e83 cdb0b4e 63c9e83 88e3654 999146f 88e3654 63c9e83 1f6e19d 88e3654 948de27 81368b8 e4c65e7 948de27 81368b8 948de27 81368b8 948de27 88e3654 2f6e05a 88e3654 81368b8 88e3654 f8e43b5 cb10dbd f8e43b5 e4c65e7 dfb9bd5 81368b8 e41e310 63c9e83 e4c65e7 f8e43b5 e4c65e7 f8e43b5 e4c65e7 88e3654 e4c65e7 fcc30c7 e4c65e7 fcc30c7 e4c65e7 e41e310 e4c65e7 f8e43b5 e41e310 81368b8 e7de586 2f6e05a e7de586 86f68fe 4da79e9 86f68fe e7de586 dfb9bd5 63c9e83 e7de586 63c9e83 e7de586 2ccf758 63c9e83 2ccf758 63c9e83 2ccf758 e7de586 2ccf758 63c9e83 2ccf758 e7de586 2f6e05a 88e3654 2f6e05a dfb9bd5 63c9e83 75e71e7 88e3654 75e71e7 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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# import os
# import datasets
# import tarfile
# _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 and tracking.
# """
# _TRAIN_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_images.tar.gz"
# _TEST_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_images.tar.gz"
# _TRAIN_ANNOTATION_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_annotation.tar.gz"
# _TEST_ANNOTATION_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_annotation.tar.gz"
# class EMT(datasets.GeneratorBasedBuilder):
# """EMT dataset."""
# BUILDER_CONFIGS = [
# datasets.BuilderConfig(
# name="full_size",
# description="All images are in their original size.",
# version=datasets.Version("1.0.0"),
# )
# ]
# def _info(self):
# return datasets.DatasetInfo(
# description=_DESCRIPTION,
# features=datasets.Features(
# {
# "image": datasets.Image(),
# "objects": datasets.Sequence(
# {
# "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
# "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):
# """Download (if not cached) and prepare dataset splits."""
# image_urls = {
# "train": _TRAIN_IMAGE_ARCHIVE_URL,
# "test": _TEST_IMAGE_ARCHIVE_URL,
# }
# annotation_urls = {
# "train": _TRAIN_ANNOTATION_ARCHIVE_URL,
# "test": _TEST_ANNOTATION_ARCHIVE_URL,
# }
# # Based on the requested split, we only download the relevant data
# split = self.config.name # Determine the requested split (train or test)
# # Ensure paths are correctly resolved for the requested split
# extracted_paths = dl_manager.download_and_extract({split: annotation_urls[split]})
# image_archives = dl_manager.download_and_extract({split: image_urls[split]})
# # Ensure annotation paths point to the correct subdirectory
# annotation_path = os.path.join(extracted_paths[split], "annotations", split)
# image_path = image_archives[split]
# return [
# datasets.SplitGenerator(
# name=datasets.Split.TRAIN if split == "train" else datasets.Split.TEST,
# gen_kwargs={
# "images": dl_manager.iter_archive(image_path),
# "annotation_path": annotation_path,
# },
# ),
# ]
# # def _split_generators(self, dl_manager):
# # """Download (if not cached) and prepare dataset splits."""
# # image_urls = {
# # "train": _TRAIN_IMAGE_ARCHIVE_URL,
# # "test": _TEST_IMAGE_ARCHIVE_URL,
# # }
# # annotation_urls = {
# # "train": _TRAIN_ANNOTATION_ARCHIVE_URL,
# # "test": _TEST_ANNOTATION_ARCHIVE_URL,
# # }
# # # Ensure paths are correctly resolved
# # extracted_paths = dl_manager.download_and_extract(annotation_urls)
# # image_archives = dl_manager.download_and_extract(image_urls)
# # # ✅ Ensure annotation paths point to the correct subdirectory
# # train_annotation_path = os.path.join(extracted_paths["train"], "annotations", "train")
# # test_annotation_path = os.path.join(extracted_paths["test"], "annotations", "test")
# # return [
# # datasets.SplitGenerator(
# # name=datasets.Split.TRAIN,
# # gen_kwargs={
# # "images": dl_manager.iter_archive(image_archives["train"]),
# # "annotation_path": train_annotation_path, # ✅ Corrected path
# # },
# # ),
# # datasets.SplitGenerator(
# # name=datasets.Split.TEST,
# # gen_kwargs={
# # "images": dl_manager.iter_archive(image_archives["test"]),
# # "annotation_path": test_annotation_path, # ✅ Corrected path
# # },
# # ),
# # ]
# def _generate_examples(self, images, annotation_path):
# """Generate dataset examples by matching images to their corresponding annotations."""
# annotations = {}
# # Determine whether we're processing train or test split
# if "train" in annotation_path:
# annotation_split = "train"
# elif "test" in annotation_path:
# annotation_split = "test"
# else:
# raise ValueError(f"Unknown annotation path: {annotation_path}")
# ann_dir = annotation_path
# print(f"Extracted annotations path: {annotation_path}")
# print(f"Looking for annotations in: {ann_dir}")
# # Check if annotation directory exists
# if not os.path.exists(ann_dir):
# raise FileNotFoundError(f"Annotation directory does not exist: {ann_dir}")
# # Extract annotation files and read their contents
# for ann_file in os.listdir(ann_dir):
# video_name = os.path.splitext(ann_file)[0] # Extract video folder name from file
# ann_path = os.path.join(ann_dir, ann_file)
# if os.path.isdir(ann_path):
# continue # Skip directories
# print("Processing annotation file:", ann_path)
# with open(ann_path, "r", encoding="utf-8") as f:
# for line in f:
# parts = line.strip().split()
# if len(parts) < 8:
# continue
# frame_id, track_id, class_name = parts[:3]
# bbox = list(map(float, parts[4:8]))
# class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
# img_name = f"{frame_id}.jpg"
# # Store annotation in a dictionary
# key = f"{video_name}/{img_name}"
# if key not in annotations:
# annotations[key] = []
# annotations[key].append(
# {
# "bbox": bbox,
# "class_id": class_id,
# "track_id": int(track_id),
# "class_name": class_name,
# }
# )
# # Yield dataset entries
# idx = 0
# for file_path, file_obj in images:
# img_name = os.path.basename(file_path)
# video_name = os.path.basename(os.path.dirname(file_path)) # Match the video folder
# key = f"{video_name}/{img_name}"
# if key in annotations:
# yield idx, {
# "image": {"path": file_path, "bytes": file_obj.read()},
# "objects": annotations[key],
# }
# idx += 1
import os
import datasets
import tarfile
_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 and tracking.
"""
_TRAIN_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_images.tar.gz"
_TEST_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_images.tar.gz"
_TRAIN_ANNOTATION_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_annotation.tar.gz"
_TEST_ANNOTATION_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_annotation.tar.gz"
_GT_OBJECT_CLASSES = {
0: "Pedestrian",
1: "Cyclist",
2: "Motorbike",
3: "Small_motorised_vehicle",
4: "Car",
5: "Medium_vehicle",
6: "Large_vehicle",
7: "Bus",
8: "Emergency_vehicle",
}
class EMT(datasets.GeneratorBasedBuilder):
"""EMT dataset."""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="emt",
description="Training split of the EMT dataset",
version=datasets.Version("1.0.0"),
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"image": datasets.Image(),
"objects": datasets.Sequence(
{
"bbox": datasets.Sequence(datasets.Value("float32"), length=4),
"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):
# """Download (if not cached) and prepare dataset splits."""
# image_urls = {
# "train": _TRAIN_IMAGE_ARCHIVE_URL,
# "test": _TEST_IMAGE_ARCHIVE_URL,
# }
# annotation_urls = {
# "train": _TRAIN_ANNOTATION_ARCHIVE_URL,
# "test": _TEST_ANNOTATION_ARCHIVE_URL,
# }
# # Ensure paths are correctly resolved for the requested split
# extracted_paths = dl_manager.download_and_extract(annotation_urls)
# image_archives = dl_manager.download_and_extract(image_urls)
# # Ensure annotation paths point to the correct subdirectory
# train_annotation_path = os.path.join(extracted_paths["train"], "EMT", "annotations", "train")
# test_annotation_path = os.path.join(extracted_paths["test"], "EMT", "annotations", "test")
# return [
# datasets.SplitGenerator(
# name=datasets.Split.TRAIN,
# gen_kwargs={
# "images": dl_manager.iter_archive(image_archives["train"]),
# "annotation_path": train_annotation_path,
# },
# ),
# datasets.SplitGenerator(
# name=datasets.Split.TEST,
# gen_kwargs={
# "images": dl_manager.iter_archive(image_archives["test"]),
# "annotation_path": test_annotation_path,
# },
# ),
# ]
def _split_generators(self, dl_manager):
"""Download (if not cached) and prepare dataset splits."""
# Define dataset URLs
image_urls = {
"train": _TRAIN_IMAGE_ARCHIVE_URL,
"test": _TEST_IMAGE_ARCHIVE_URL,
}
annotation_urls = {
"train": _TRAIN_ANNOTATION_ARCHIVE_URL,
"test": _TEST_ANNOTATION_ARCHIVE_URL,
}
# Extract all data (both splits)
extracted_images = dl_manager.download_and_extract(image_urls)
extracted_annotations = dl_manager.download_and_extract(annotation_urls)
# Define paths
train_annotation_path = os.path.join(extracted_annotations["train"], "annotations", "train")
test_annotation_path = os.path.join(extracted_annotations["test"], "annotations", "test")
train_image_path = extracted_images["train"]
test_image_path = extracted_images["test"]
# Return available splits (Hugging Face will filter based on user request)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"image_dir": train_image_path,
"annotation_path": train_annotation_path,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"image_dir": test_image_path,
"annotation_path": test_annotation_path,
},
),
]
def _generate_examples(self, images, annotation_path):
"""Generate dataset examples by matching images to their corresponding annotations."""
annotations = {}
# Determine whether we're processing train or test split
if "train" in annotation_path:
annotation_split = "train"
elif "test" in annotation_path:
annotation_split = "test"
else:
raise ValueError(f"Unknown annotation path: {annotation_path}")
ann_dir = annotation_path
print(f"Extracted annotations path: {annotation_path}")
print(f"Looking for annotations in: {ann_dir}")
# Check if annotation directory exists
if not os.path.exists(ann_dir):
raise FileNotFoundError(f"Annotation directory does not exist: {ann_dir}")
# Extract annotation files and read their contents
for ann_file in os.listdir(ann_dir):
video_name = os.path.splitext(ann_file)[0] # Extract video folder name from file
ann_path = os.path.join(ann_dir, ann_file)
if os.path.isdir(ann_path):
continue # Skip directories
print("Processing annotation file:", ann_path)
with open(ann_path, "r", encoding="utf-8") as f:
for line in f:
parts = line.strip().split()
if len(parts) < 8:
continue
frame_id, track_id, class_name = parts[:3]
bbox = list(map(float, parts[4:8]))
class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
img_name = f"{frame_id}.jpg"
# Store annotation in a dictionary
key = f"{video_name}/{img_name}"
if key not in annotations:
annotations[key] = []
annotations[key].append(
{
"bbox": bbox,
"class_id": class_id,
"track_id": int(track_id),
"class_name": class_name,
}
)
# Yield dataset entries
idx = 0
for file_path, file_obj in images:
img_name = os.path.basename(file_path)
video_name = os.path.basename(os.path.dirname(file_path)) # Match the video folder
key = f"{video_name}/{img_name}"
if key in annotations:
yield idx, {
"image": {"path": file_path, "bytes": file_obj.read()},
"objects": annotations[key],
}
idx += 1
|