# 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. | |
# """ | |
# # # Annotation repository | |
# # _ANNOTATION_REPO = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/annotations" | |
# # Tar file URLs for images | |
# _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" | |
# # Tar file URLs for annotations | |
# _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 train/test images and annotations.""" | |
# image_urls = { | |
# "train": _TRAIN_IMAGE_ARCHIVE_URL, | |
# "test": _TEST_IMAGE_ARCHIVE_URL, | |
# } | |
# # Download the tar file for annotations | |
# # annotation_urls = { | |
# # "train": _TRAIN_ANNOTATION_ARCHIVE_URL, | |
# # "test": _TEST_ANNOTATION_ARCHIVE_URL, | |
# # } | |
# annotation_urls = { | |
# "train": "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_annotation.tar.gz", | |
# "test": "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_annotation.tar.gz", | |
# } | |
# # Download image files | |
# images = { | |
# "train": dl_manager.iter_archive(image_urls["train"]), | |
# "test": dl_manager.iter_archive(image_urls["test"]), | |
# } | |
# # Download annotation files and extract them | |
# annotations = { | |
# "train": dl_manager.download_and_extract(annotation_urls["train"]), | |
# "test": dl_manager.download_and_extract(annotation_urls["test"]), | |
# } | |
# return [ | |
# datasets.SplitGenerator( | |
# name=datasets.Split.TRAIN, | |
# gen_kwargs={ | |
# "images": images["train"], | |
# "annotation_path": annotations["train"], | |
# }, | |
# ), | |
# datasets.SplitGenerator( | |
# name=datasets.Split.TEST, | |
# gen_kwargs={ | |
# "images": images["test"], | |
# "annotation_path": annotations["test"], | |
# }, | |
# ), | |
# ] | |
# def _generate_examples(self, images, annotation_path): | |
# """Generate dataset examples by matching images to their corresponding annotations.""" | |
# annotations = {} | |
# # Load all annotations into memory | |
# for ann_file in os.listdir(annotation_path): | |
# video_name = os.path.splitext(ann_file)[0] # Get video folder name from the annotation file | |
# ann_path = os.path.join(annotation_path, ann_file) | |
# print("ann_path:,",ann_path,"\nannotation_path: ",annotation_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" | |
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 train/test images and annotations.""" | |
image_urls = { | |
"train": _TRAIN_IMAGE_ARCHIVE_URL, | |
"test": _TEST_IMAGE_ARCHIVE_URL, | |
} | |
annotation_urls = { | |
"train": _TRAIN_ANNOTATION_ARCHIVE_URL, | |
"test": _TEST_ANNOTATION_ARCHIVE_URL, | |
} | |
# Download image files | |
images = { | |
"train": dl_manager.iter_archive(image_urls["train"]), | |
"test": dl_manager.iter_archive(image_urls["test"]), | |
} | |
# Download annotation files and extract them | |
annotations = { | |
"train": dl_manager.download_and_extract(annotation_urls["train"]), | |
"test": dl_manager.download_and_extract(annotation_urls["test"]), | |
} | |
return [ | |
datasets.SplitGenerator( | |
name=datasets.Split.TRAIN, | |
gen_kwargs={ | |
"images": images["train"], | |
"annotation_path": annotations["train"], | |
}, | |
), | |
datasets.SplitGenerator( | |
name=datasets.Split.TEST, | |
gen_kwargs={ | |
"images": images["test"], | |
"annotation_path": annotations["test"], | |
}, | |
), | |
] | |
def _generate_examples(self, images, annotation_path): | |
"""Generate dataset examples by matching images to their corresponding annotations.""" | |
annotations = {} | |
# Extract annotation tar file and read its contents | |
for ann_file in os.listdir(annotation_path): | |
# Ensure that we're dealing with the annotation file | |
ann_path = os.path.join(annotation_path, 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"{ann_file}/{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 | |