Update EMT.py
Browse files
EMT.py
CHANGED
|
@@ -163,14 +163,33 @@
|
|
| 163 |
|
| 164 |
import os
|
| 165 |
import datasets
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
-
# Tar file URLs for images
|
| 171 |
_TRAIN_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_images.tar.gz"
|
| 172 |
_TEST_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_images.tar.gz"
|
| 173 |
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
class EMT(datasets.GeneratorBasedBuilder):
|
| 176 |
"""EMT dataset."""
|
|
@@ -211,24 +230,24 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 211 |
"train": _TRAIN_IMAGE_ARCHIVE_URL,
|
| 212 |
"test": _TEST_IMAGE_ARCHIVE_URL,
|
| 213 |
}
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
# Download image files
|
| 216 |
images = {
|
| 217 |
"train": dl_manager.iter_archive(image_urls["train"]),
|
| 218 |
"test": dl_manager.iter_archive(image_urls["test"]),
|
| 219 |
}
|
| 220 |
-
|
| 221 |
-
# Download
|
| 222 |
-
annotation_urls = {
|
| 223 |
-
"train": _ANNOTATION_REPO + "/train/",
|
| 224 |
-
"test": _ANNOTATION_REPO + "/test/",
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
annotations = {
|
| 228 |
"train": dl_manager.download_and_extract(annotation_urls["train"]),
|
| 229 |
"test": dl_manager.download_and_extract(annotation_urls["test"]),
|
| 230 |
}
|
| 231 |
-
|
| 232 |
return [
|
| 233 |
datasets.SplitGenerator(
|
| 234 |
name=datasets.Split.TRAIN,
|
|
@@ -251,29 +270,32 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 251 |
|
| 252 |
annotations = {}
|
| 253 |
|
| 254 |
-
#
|
| 255 |
for ann_file in os.listdir(annotation_path):
|
| 256 |
-
#
|
| 257 |
-
video_name = os.path.splitext(ann_file)[0]
|
| 258 |
ann_path = os.path.join(annotation_path, ann_file)
|
| 259 |
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
with open(ann_path, "r", encoding="utf-8") as f:
|
| 262 |
for line in f:
|
| 263 |
parts = line.strip().split()
|
| 264 |
if len(parts) < 8:
|
| 265 |
continue
|
| 266 |
-
|
| 267 |
frame_id, track_id, class_name = parts[:3]
|
| 268 |
bbox = list(map(float, parts[4:8]))
|
| 269 |
class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
|
| 270 |
img_name = f"{frame_id}.jpg"
|
| 271 |
-
|
| 272 |
# Store annotation in a dictionary
|
| 273 |
-
key = f"{
|
| 274 |
if key not in annotations:
|
| 275 |
annotations[key] = []
|
| 276 |
-
|
| 277 |
annotations[key].append(
|
| 278 |
{
|
| 279 |
"bbox": bbox,
|
|
@@ -289,10 +311,11 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 289 |
img_name = os.path.basename(file_path)
|
| 290 |
video_name = os.path.basename(os.path.dirname(file_path)) # Match the video folder
|
| 291 |
key = f"{video_name}/{img_name}"
|
| 292 |
-
|
| 293 |
if key in annotations:
|
| 294 |
yield idx, {
|
| 295 |
"image": {"path": file_path, "bytes": file_obj.read()},
|
| 296 |
"objects": annotations[key],
|
| 297 |
}
|
| 298 |
idx += 1
|
|
|
|
|
|
| 163 |
|
| 164 |
import os
|
| 165 |
import datasets
|
| 166 |
+
import tarfile
|
| 167 |
|
| 168 |
+
_HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"
|
| 169 |
+
_LICENSE = "CC-BY-SA 4.0"
|
| 170 |
+
_CITATION = """
|
| 171 |
+
@article{EMTdataset2025,
|
| 172 |
+
title={EMT: A Visual Multi-Task Benchmark Dataset for Autonomous Driving in the Arab Gulf Region},
|
| 173 |
+
author={Nadya Abdel Madjid and Murad Mebrahtu and Abdelmoamen Nasser and Bilal Hassan and Naoufel Werghi and Jorge Dias and Majid Khonji},
|
| 174 |
+
year={2025},
|
| 175 |
+
eprint={2502.19260},
|
| 176 |
+
archivePrefix={arXiv},
|
| 177 |
+
primaryClass={cs.CV},
|
| 178 |
+
url={https://arxiv.org/abs/2502.19260}
|
| 179 |
+
}
|
| 180 |
+
"""
|
| 181 |
+
|
| 182 |
+
_DESCRIPTION = """\
|
| 183 |
+
A multi-task dataset for detection, tracking, prediction, and intention prediction.
|
| 184 |
+
This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection and tracking.
|
| 185 |
+
"""
|
| 186 |
|
|
|
|
| 187 |
_TRAIN_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_images.tar.gz"
|
| 188 |
_TEST_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_images.tar.gz"
|
| 189 |
|
| 190 |
+
_TRAIN_ANNOTATION_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_annotation.tar.gz"
|
| 191 |
+
_TEST_ANNOTATION_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/test_annotation.tar.gz"
|
| 192 |
+
|
| 193 |
|
| 194 |
class EMT(datasets.GeneratorBasedBuilder):
|
| 195 |
"""EMT dataset."""
|
|
|
|
| 230 |
"train": _TRAIN_IMAGE_ARCHIVE_URL,
|
| 231 |
"test": _TEST_IMAGE_ARCHIVE_URL,
|
| 232 |
}
|
| 233 |
+
|
| 234 |
+
annotation_urls = {
|
| 235 |
+
"train": _TRAIN_ANNOTATION_ARCHIVE_URL,
|
| 236 |
+
"test": _TEST_ANNOTATION_ARCHIVE_URL,
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
# Download image files
|
| 240 |
images = {
|
| 241 |
"train": dl_manager.iter_archive(image_urls["train"]),
|
| 242 |
"test": dl_manager.iter_archive(image_urls["test"]),
|
| 243 |
}
|
| 244 |
+
|
| 245 |
+
# Download annotation files and extract them
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
annotations = {
|
| 247 |
"train": dl_manager.download_and_extract(annotation_urls["train"]),
|
| 248 |
"test": dl_manager.download_and_extract(annotation_urls["test"]),
|
| 249 |
}
|
| 250 |
+
|
| 251 |
return [
|
| 252 |
datasets.SplitGenerator(
|
| 253 |
name=datasets.Split.TRAIN,
|
|
|
|
| 270 |
|
| 271 |
annotations = {}
|
| 272 |
|
| 273 |
+
# Extract annotation tar file and read its contents
|
| 274 |
for ann_file in os.listdir(annotation_path):
|
| 275 |
+
# Ensure that we're dealing with the annotation file
|
|
|
|
| 276 |
ann_path = os.path.join(annotation_path, ann_file)
|
| 277 |
|
| 278 |
+
if os.path.isdir(ann_path):
|
| 279 |
+
continue # Skip directories
|
| 280 |
+
|
| 281 |
+
print("Processing annotation file:", ann_path)
|
| 282 |
+
|
| 283 |
with open(ann_path, "r", encoding="utf-8") as f:
|
| 284 |
for line in f:
|
| 285 |
parts = line.strip().split()
|
| 286 |
if len(parts) < 8:
|
| 287 |
continue
|
| 288 |
+
|
| 289 |
frame_id, track_id, class_name = parts[:3]
|
| 290 |
bbox = list(map(float, parts[4:8]))
|
| 291 |
class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
|
| 292 |
img_name = f"{frame_id}.jpg"
|
| 293 |
+
|
| 294 |
# Store annotation in a dictionary
|
| 295 |
+
key = f"{ann_file}/{img_name}"
|
| 296 |
if key not in annotations:
|
| 297 |
annotations[key] = []
|
| 298 |
+
|
| 299 |
annotations[key].append(
|
| 300 |
{
|
| 301 |
"bbox": bbox,
|
|
|
|
| 311 |
img_name = os.path.basename(file_path)
|
| 312 |
video_name = os.path.basename(os.path.dirname(file_path)) # Match the video folder
|
| 313 |
key = f"{video_name}/{img_name}"
|
| 314 |
+
|
| 315 |
if key in annotations:
|
| 316 |
yield idx, {
|
| 317 |
"image": {"path": file_path, "bytes": file_obj.read()},
|
| 318 |
"objects": annotations[key],
|
| 319 |
}
|
| 320 |
idx += 1
|
| 321 |
+
|