jherng commited on
Commit
851929c
1 Parent(s): cc5ed83

Update xd-violence.py

Browse files
Files changed (1) hide show
  1. xd-violence.py +3 -21
xd-violence.py CHANGED
@@ -199,12 +199,6 @@ class XDViolence(datasets.GeneratorBasedBuilder):
199
  "test": dl_manager.download(video_urls["test"]),
200
  }
201
 
202
- # Function to read annotations
203
- annotation_readers = {
204
- "train": self._read_list,
205
- "test": self._read_list,
206
- }
207
-
208
  return [
209
  datasets.SplitGenerator(
210
  name=datasets.Split.TRAIN,
@@ -212,7 +206,6 @@ class XDViolence(datasets.GeneratorBasedBuilder):
212
  "list_path": list_paths["train"],
213
  "frame_annotation_path": None,
214
  "video_paths": video_paths["train"],
215
- "annotation_reader": annotation_readers["train"],
216
  },
217
  ),
218
  datasets.SplitGenerator(
@@ -221,20 +214,15 @@ class XDViolence(datasets.GeneratorBasedBuilder):
221
  "list_path": list_paths["test"],
222
  "frame_annotation_path": annotation_path,
223
  "video_paths": video_paths["test"],
224
- "annotation_reader": annotation_readers["test"],
225
  },
226
  ),
227
  ]
228
 
229
- def _generate_examples(
230
- self, list_path, frame_annotation_path, video_paths, annotation_reader
231
- ):
232
  if self.config.name == "rgb":
233
  raise NotImplementedError("rgb not implemented yet")
234
  else:
235
- print(f"{list_path=}")
236
- print(f"{frame_annotation_path=}")
237
- ann_data = annotation_reader(list_path, frame_annotation_path)
238
 
239
  for key, (path, annotation) in enumerate(zip(video_paths, ann_data)):
240
  id = annotation["id"]
@@ -267,12 +255,9 @@ class XDViolence(datasets.GeneratorBasedBuilder):
267
 
268
  if frame_annotation_path: # test set
269
  id2frame_annotation = {}
270
- print(frame_annotation_path)
271
- print(id2frame_annotation)
272
 
273
  url_components = urllib.parse.urlparse(frame_annotation_path)
274
  is_url = url_components.scheme in ("http", "https")
275
- print(f"{is_url=}")
276
  if is_url:
277
  with requests.get(frame_annotation_path, stream=True) as r:
278
  r.raise_for_status()
@@ -299,13 +284,10 @@ class XDViolence(datasets.GeneratorBasedBuilder):
299
  ]
300
 
301
  id2frame_annotation[id] = frame_annotation
302
- print(id2frame_annotation)
303
- print(file_list.head())
304
 
305
  file_list["frame_annotations"] = file_list["id"].apply(
306
- lambda x: id2frame_annotation[x] if x in id2frame_annotation else []
307
  )
308
- print(file_list.head())
309
 
310
  return file_list.to_dict("records")
311
 
 
199
  "test": dl_manager.download(video_urls["test"]),
200
  }
201
 
 
 
 
 
 
 
202
  return [
203
  datasets.SplitGenerator(
204
  name=datasets.Split.TRAIN,
 
206
  "list_path": list_paths["train"],
207
  "frame_annotation_path": None,
208
  "video_paths": video_paths["train"],
 
209
  },
210
  ),
211
  datasets.SplitGenerator(
 
214
  "list_path": list_paths["test"],
215
  "frame_annotation_path": annotation_path,
216
  "video_paths": video_paths["test"],
 
217
  },
218
  ),
219
  ]
220
 
221
+ def _generate_examples(self, list_path, frame_annotation_path, video_paths):
 
 
222
  if self.config.name == "rgb":
223
  raise NotImplementedError("rgb not implemented yet")
224
  else:
225
+ ann_data = self._read_list(list_path, frame_annotation_path)
 
 
226
 
227
  for key, (path, annotation) in enumerate(zip(video_paths, ann_data)):
228
  id = annotation["id"]
 
255
 
256
  if frame_annotation_path: # test set
257
  id2frame_annotation = {}
 
 
258
 
259
  url_components = urllib.parse.urlparse(frame_annotation_path)
260
  is_url = url_components.scheme in ("http", "https")
 
261
  if is_url:
262
  with requests.get(frame_annotation_path, stream=True) as r:
263
  r.raise_for_status()
 
284
  ]
285
 
286
  id2frame_annotation[id] = frame_annotation
 
 
287
 
288
  file_list["frame_annotations"] = file_list["id"].apply(
289
+ lambda x: id2frame_annotation[x] if x in id2frame_annotation else None
290
  )
 
291
 
292
  return file_list.to_dict("records")
293