KuAvLab commited on
Commit
4b9d07c
·
verified ·
1 Parent(s): 4fdd18a

Update EMT.py

Browse files
Files changed (1) hide show
  1. EMT.py +21 -20
EMT.py CHANGED
@@ -3,7 +3,6 @@
3
  import os
4
  import datasets
5
 
6
-
7
  _HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"
8
 
9
  _LICENSE = "CC-BY-SA 4.0"
@@ -22,11 +21,11 @@ _CITATION = """
22
 
23
  _DESCRIPTION = """\
24
  A multi-task dataset for detection, tracking, prediction, and intention prediction.
25
- This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection + tracking.
26
  """
27
 
28
  # Annotation repository
29
- _ANNOTATION_REPO = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/annotations/"
30
 
31
  # Tar file URLs for images
32
  _TRAIN_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_images.tar.gz"
@@ -68,55 +67,57 @@ class EMT(datasets.GeneratorBasedBuilder):
68
 
69
  def _split_generators(self, dl_manager):
70
  """Download train/test images and annotations."""
71
- image_urls = {
72
- "train": _TRAIN_IMAGE_ARCHIVE_URL,
73
- "test": _TEST_IMAGE_ARCHIVE_URL,
 
 
74
  }
75
-
 
76
  annotation_paths = {
77
- "train": dl_manager.download_and_extract(f"{_ANNOTATION_REPO}/train/"),
78
- "test": dl_manager.download_and_extract(f"{_ANNOTATION_REPO}/test/"),
79
  }
80
-
81
  return [
82
  datasets.SplitGenerator(
83
  name=datasets.Split.TRAIN,
84
  gen_kwargs={
85
- "images": dl_manager.iter_archive(image_urls["train"]),
86
  "annotation_path": annotation_paths["train"],
87
  },
88
  ),
89
  datasets.SplitGenerator(
90
  name=datasets.Split.TEST,
91
  gen_kwargs={
92
- "images": dl_manager.iter_archive(image_urls["test"]),
93
  "annotation_path": annotation_paths["test"],
94
  },
95
  ),
96
  ]
97
 
98
-
99
  def _generate_examples(self, images, annotation_path):
100
  """Generate dataset examples by matching images to their corresponding annotations."""
101
 
102
  # Load ALL annotations into memory before iterating over images
103
  annotations = {}
104
-
105
  for ann_file in os.listdir(annotation_path): # Iterate over all annotation files
106
- video_name = os.path.splitext(ann_file)[0] # Extract video folder name
107
  ann_path = os.path.join(annotation_path, ann_file)
108
-
 
109
  with open(ann_path, "r", encoding="utf-8") as f:
110
  for line in f:
111
  parts = line.strip().split()
112
  if len(parts) < 8:
113
  continue
114
-
115
  frame_id, track_id, class_name = parts[:3]
116
  bbox = list(map(float, parts[4:8]))
117
  class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
118
  img_name = f"{frame_id}.jpg"
119
-
120
  # Store annotation in a simple dictionary
121
  key = f"{video_name}/{img_name}"
122
  if key not in annotations:
@@ -130,14 +131,14 @@ class EMT(datasets.GeneratorBasedBuilder):
130
  "class_name": class_name,
131
  }
132
  )
133
-
134
  # Yield dataset entries
135
  idx = 0
136
  for file_path, file_obj in images:
137
  img_name = os.path.basename(file_path)
138
  video_name = os.path.basename(os.path.dirname(file_path))
139
  key = f"{video_name}/{img_name}" # Match image to preloaded annotations
140
-
141
  if key in annotations:
142
  yield idx, {
143
  "image": {"path": file_path, "bytes": file_obj.read()},
 
3
  import os
4
  import datasets
5
 
 
6
  _HOMEPAGE = "https://github.com/AV-Lab/emt-dataset"
7
 
8
  _LICENSE = "CC-BY-SA 4.0"
 
21
 
22
  _DESCRIPTION = """\
23
  A multi-task dataset for detection, tracking, prediction, and intention prediction.
24
+ This dataset includes 34,386 annotated frames collected over 57 minutes of driving, with annotations for detection and tracking.
25
  """
26
 
27
  # Annotation repository
28
+ _ANNOTATION_REPO = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/annotations"
29
 
30
  # Tar file URLs for images
31
  _TRAIN_IMAGE_ARCHIVE_URL = "https://huggingface.co/datasets/KuAvLab/EMT/resolve/main/train_images.tar.gz"
 
67
 
68
  def _split_generators(self, dl_manager):
69
  """Download train/test images and annotations."""
70
+
71
+ # Download and extract images
72
+ image_paths = {
73
+ "train": dl_manager.download_and_extract(_TRAIN_IMAGE_ARCHIVE_URL),
74
+ "test": dl_manager.download_and_extract(_TEST_IMAGE_ARCHIVE_URL),
75
  }
76
+
77
+ # Download annotations (extracted automatically)
78
  annotation_paths = {
79
+ "train": dl_manager.download_and_extract(f"{_ANNOTATION_REPO}/train"),
80
+ "test": dl_manager.download_and_extract(f"{_ANNOTATION_REPO}/test"),
81
  }
82
+
83
  return [
84
  datasets.SplitGenerator(
85
  name=datasets.Split.TRAIN,
86
  gen_kwargs={
87
+ "images": dl_manager.iter_archive(image_paths["train"]),
88
  "annotation_path": annotation_paths["train"],
89
  },
90
  ),
91
  datasets.SplitGenerator(
92
  name=datasets.Split.TEST,
93
  gen_kwargs={
94
+ "images": dl_manager.iter_archive(image_paths["test"]),
95
  "annotation_path": annotation_paths["test"],
96
  },
97
  ),
98
  ]
99
 
 
100
  def _generate_examples(self, images, annotation_path):
101
  """Generate dataset examples by matching images to their corresponding annotations."""
102
 
103
  # Load ALL annotations into memory before iterating over images
104
  annotations = {}
105
+
106
  for ann_file in os.listdir(annotation_path): # Iterate over all annotation files
 
107
  ann_path = os.path.join(annotation_path, ann_file)
108
+ video_name = os.path.splitext(ann_file)[0] # Extract video folder name
109
+
110
  with open(ann_path, "r", encoding="utf-8") as f:
111
  for line in f:
112
  parts = line.strip().split()
113
  if len(parts) < 8:
114
  continue
115
+
116
  frame_id, track_id, class_name = parts[:3]
117
  bbox = list(map(float, parts[4:8]))
118
  class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
119
  img_name = f"{frame_id}.jpg"
120
+
121
  # Store annotation in a simple dictionary
122
  key = f"{video_name}/{img_name}"
123
  if key not in annotations:
 
131
  "class_name": class_name,
132
  }
133
  )
134
+
135
  # Yield dataset entries
136
  idx = 0
137
  for file_path, file_obj in images:
138
  img_name = os.path.basename(file_path)
139
  video_name = os.path.basename(os.path.dirname(file_path))
140
  key = f"{video_name}/{img_name}" # Match image to preloaded annotations
141
+
142
  if key in annotations:
143
  yield idx, {
144
  "image": {"path": file_path, "bytes": file_obj.read()},