Update EMT.py
Browse files
EMT.py
CHANGED
|
@@ -266,23 +266,28 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 266 |
"annotation_path": annotations["test"],
|
| 267 |
},
|
| 268 |
),
|
| 269 |
-
|
| 270 |
-
|
| 271 |
def _generate_examples(self, images, annotation_path):
|
| 272 |
"""Generate dataset examples by matching images to their corresponding annotations."""
|
| 273 |
-
|
| 274 |
annotations = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
| 280 |
|
| 281 |
if os.path.isdir(ann_path):
|
| 282 |
continue # Skip directories
|
| 283 |
-
|
| 284 |
print("Processing annotation file:", ann_path)
|
| 285 |
-
|
| 286 |
with open(ann_path, "r", encoding="utf-8") as f:
|
| 287 |
for line in f:
|
| 288 |
parts = line.strip().split()
|
|
@@ -295,7 +300,7 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 295 |
img_name = f"{frame_id}.jpg"
|
| 296 |
|
| 297 |
# Store annotation in a dictionary
|
| 298 |
-
key = f"{
|
| 299 |
if key not in annotations:
|
| 300 |
annotations[key] = []
|
| 301 |
|
|
@@ -307,7 +312,7 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 307 |
"class_name": class_name,
|
| 308 |
}
|
| 309 |
)
|
| 310 |
-
|
| 311 |
# Yield dataset entries
|
| 312 |
idx = 0
|
| 313 |
for file_path, file_obj in images:
|
|
@@ -322,3 +327,4 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 322 |
}
|
| 323 |
idx += 1
|
| 324 |
|
|
|
|
|
|
| 266 |
"annotation_path": annotations["test"],
|
| 267 |
},
|
| 268 |
),
|
| 269 |
+
]
|
|
|
|
| 270 |
def _generate_examples(self, images, annotation_path):
|
| 271 |
"""Generate dataset examples by matching images to their corresponding annotations."""
|
| 272 |
+
|
| 273 |
annotations = {}
|
| 274 |
+
|
| 275 |
+
# Ensure we access the correct annotation subdirectory
|
| 276 |
+
annotation_split = "train" if "train" in annotation_path else "test"
|
| 277 |
+
ann_dir = os.path.join(annotation_path, "annotations", annotation_split)
|
| 278 |
|
| 279 |
+
print("Looking for annotations in:", ann_dir)
|
| 280 |
+
|
| 281 |
+
# Extract annotation files and read their contents
|
| 282 |
+
for ann_file in os.listdir(ann_dir):
|
| 283 |
+
video_name = os.path.splitext(ann_file)[0] # Extract video folder name from file
|
| 284 |
+
ann_path = os.path.join(ann_dir, ann_file)
|
| 285 |
|
| 286 |
if os.path.isdir(ann_path):
|
| 287 |
continue # Skip directories
|
| 288 |
+
|
| 289 |
print("Processing annotation file:", ann_path)
|
| 290 |
+
|
| 291 |
with open(ann_path, "r", encoding="utf-8") as f:
|
| 292 |
for line in f:
|
| 293 |
parts = line.strip().split()
|
|
|
|
| 300 |
img_name = f"{frame_id}.jpg"
|
| 301 |
|
| 302 |
# Store annotation in a dictionary
|
| 303 |
+
key = f"{video_name}/{img_name}"
|
| 304 |
if key not in annotations:
|
| 305 |
annotations[key] = []
|
| 306 |
|
|
|
|
| 312 |
"class_name": class_name,
|
| 313 |
}
|
| 314 |
)
|
| 315 |
+
|
| 316 |
# Yield dataset entries
|
| 317 |
idx = 0
|
| 318 |
for file_path, file_obj in images:
|
|
|
|
| 327 |
}
|
| 328 |
idx += 1
|
| 329 |
|
| 330 |
+
|