Update EMT.py
Browse files
EMT.py
CHANGED
@@ -110,44 +110,41 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
110 |
},
|
111 |
),
|
112 |
]
|
113 |
-
|
114 |
def _generate_examples(self, images, annotation_path):
|
115 |
"""Generate dataset examples by matching images to their corresponding annotations."""
|
116 |
|
117 |
annotations = {}
|
118 |
|
119 |
-
#
|
120 |
for ann_file in os.listdir(annotation_path):
|
121 |
-
video_name = os.path.splitext(ann_file)[0] # Get video folder name
|
122 |
ann_path = os.path.join(annotation_path, ann_file)
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
bbox = list(map(float, parts[4:8]))
|
135 |
-
class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
|
136 |
-
img_name = f"{frame_id}.jpg"
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
|
152 |
# Yield dataset entries
|
153 |
idx = 0
|
@@ -162,3 +159,4 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
162 |
"objects": annotations[key],
|
163 |
}
|
164 |
idx += 1
|
|
|
|
110 |
},
|
111 |
),
|
112 |
]
|
113 |
+
|
114 |
def _generate_examples(self, images, annotation_path):
|
115 |
"""Generate dataset examples by matching images to their corresponding annotations."""
|
116 |
|
117 |
annotations = {}
|
118 |
|
119 |
+
# Load all annotations into memory
|
120 |
for ann_file in os.listdir(annotation_path):
|
121 |
+
video_name = os.path.splitext(ann_file)[0] # Get video folder name from the annotation file
|
122 |
ann_path = os.path.join(annotation_path, ann_file)
|
123 |
|
124 |
+
with open(ann_path, "r", encoding="utf-8") as f:
|
125 |
+
for line in f:
|
126 |
+
parts = line.strip().split()
|
127 |
+
if len(parts) < 8:
|
128 |
+
continue
|
129 |
+
|
130 |
+
frame_id, track_id, class_name = parts[:3]
|
131 |
+
bbox = list(map(float, parts[4:8]))
|
132 |
+
class_id = _GT_OBJECT_CLASSES.get(class_name, -1)
|
133 |
+
img_name = f"{frame_id}.jpg"
|
|
|
|
|
|
|
134 |
|
135 |
+
# Store annotation in a dictionary
|
136 |
+
key = f"{video_name}/{img_name}"
|
137 |
+
if key not in annotations:
|
138 |
+
annotations[key] = []
|
139 |
|
140 |
+
annotations[key].append(
|
141 |
+
{
|
142 |
+
"bbox": bbox,
|
143 |
+
"class_id": class_id,
|
144 |
+
"track_id": int(track_id),
|
145 |
+
"class_name": class_name,
|
146 |
+
}
|
147 |
+
)
|
148 |
|
149 |
# Yield dataset entries
|
150 |
idx = 0
|
|
|
159 |
"objects": annotations[key],
|
160 |
}
|
161 |
idx += 1
|
162 |
+
|