KuAvLab commited on
Commit
2ccf758
·
verified ·
1 Parent(s): 0a1ee90

Update EMT.py

Browse files
Files changed (1) hide show
  1. EMT.py +26 -28
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
- # Extract the tar.gz file and read the annotations
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
- # Read annotation file
125
- with tarfile.open(ann_path, "r:gz") as tar:
126
- for member in tar.getmembers():
127
- with tar.extractfile(member) as file:
128
- for line in file:
129
- parts = line.strip().split()
130
- if len(parts) < 8:
131
- continue
132
-
133
- frame_id, track_id, class_name = parts[:3]
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
- # Store annotation in a dictionary
139
- key = f"{video_name}/{img_name}"
140
- if key not in annotations:
141
- annotations[key] = []
142
 
143
- annotations[key].append(
144
- {
145
- "bbox": bbox,
146
- "class_id": class_id,
147
- "track_id": int(track_id),
148
- "class_name": class_name,
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
+