jherng commited on
Commit
5fc19f9
1 Parent(s): 6263356

Edit dataset loading script

Browse files
Files changed (4) hide show
  1. data/train_list.txt +0 -0
  2. scripts/gen_train_list.py +1 -1
  3. test.py +0 -4
  4. xd-violence.py +44 -11
data/train_list.txt CHANGED
The diff for this file is too large to render. See raw diff
 
scripts/gen_train_list.py CHANGED
@@ -19,7 +19,7 @@ if __name__ == "__main__":
19
 
20
  try:
21
  for video in os.listdir(subdir_path):
22
- f.write(f"{subdir}/{video}\n")
23
  except FileNotFoundError as e:
24
  logger.error(
25
  f"Error processing subdir: {subdir_path}: {e.__class__.__name__}"
 
19
 
20
  try:
21
  for video in os.listdir(subdir_path):
22
+ f.write(f"{subdir}/{video.split('.mp4')[0]}\n")
23
  except FileNotFoundError as e:
24
  logger.error(
25
  f"Error processing subdir: {subdir_path}: {e.__class__.__name__}"
test.py DELETED
@@ -1,4 +0,0 @@
1
- from datasets import load_dataset
2
-
3
- ds = load_dataset("jherng/xd-violence", name="video", split="train")
4
- print(ds)
 
 
 
 
 
xd-violence.py CHANGED
@@ -1,8 +1,7 @@
1
- import json
2
  import urllib.parse
3
 
4
  import datasets
5
-
6
 
7
  _CITATION = """\
8
  @inproceedings{Wu2020not,
@@ -37,7 +36,7 @@ class XDViolenceConfig(datasets.BuilderConfig):
37
  super(XDViolenceConfig, self).__init__(**kwargs)
38
 
39
 
40
- class Squad(datasets.GeneratorBasedBuilder):
41
  BUILDER_CONFIGS = [
42
  XDViolenceConfig(
43
  name="video",
@@ -123,22 +122,56 @@ class Squad(datasets.GeneratorBasedBuilder):
123
  # Download videos
124
  # - get URLs
125
  # - download annotations
126
-
127
- train_list_fpath = dl_manager.download_and_extract(urllib.parse.urljoin(_URL, "train_list.txt"))
128
- test_ann_fpath = dl_manager.download_and_extract(urllib.parse.urljoin(_URL, "test_annotations.txt"))
129
- print(f"{train_list_fpath=}")
130
- print(f"{test_ann_fpath=}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  return [
132
  datasets.SplitGenerator(
133
  name=datasets.Split.TRAIN,
134
- gen_kwargs={"filepath": train_list_fpath},
 
 
 
135
  ),
136
  datasets.SplitGenerator(
137
  name=datasets.Split.VALIDATION,
138
- gen_kwargs={"filepath": test_ann_fpath},
 
 
 
139
  ),
140
  ]
141
 
142
- def _generate_examples(self, filepath):
143
  """This function returns the examples in the raw (text) form."""
 
144
  pass
 
 
1
  import urllib.parse
2
 
3
  import datasets
4
+ import pandas as pd
5
 
6
  _CITATION = """\
7
  @inproceedings{Wu2020not,
 
36
  super(XDViolenceConfig, self).__init__(**kwargs)
37
 
38
 
39
+ class XDViolence(datasets.GeneratorBasedBuilder):
40
  BUILDER_CONFIGS = [
41
  XDViolenceConfig(
42
  name="video",
 
122
  # Download videos
123
  # - get URLs
124
  # - download annotations
125
+
126
+ # Download annotations file
127
+ annotations_paths = {
128
+ "train": dl_manager.download_and_extract(
129
+ urllib.parse.urljoin(_URL, "train_list.txt")
130
+ ),
131
+ "test": dl_manager.download_and_extract(
132
+ urllib.parse.urljoin(_URL, "test_annotations.txt")
133
+ ),
134
+ }
135
+
136
+ # Obtain video URLs
137
+ video_urls = {
138
+ "train": pd.read_csv(
139
+ annotations_paths["train"],
140
+ header=None,
141
+ sep=" ",
142
+ usecols=[0],
143
+ names=["video_id"],
144
+ ).apply(lambda x: urllib.parse.urljoin(_URL, f"video/{x}.mp4")),
145
+ "test": pd.read_csv(
146
+ annotations_paths["test"],
147
+ header=None,
148
+ sep=" ",
149
+ usecols=[0],
150
+ names=["video_id"],
151
+ ).apply(lambda x: urllib.parse.urljoin(_URL, f"test_videos/{x}.mp4")),
152
+ }
153
+ print(video_urls["train"])
154
+ print()
155
+ print(video_urls["test"])
156
+
157
  return [
158
  datasets.SplitGenerator(
159
  name=datasets.Split.TRAIN,
160
+ gen_kwargs={
161
+ "annotation": annotations_paths["train"],
162
+ "video": video_urls["train"],
163
+ },
164
  ),
165
  datasets.SplitGenerator(
166
  name=datasets.Split.VALIDATION,
167
+ gen_kwargs={
168
+ "annotation": annotations_paths["test"],
169
+ "video": video_urls["test"],
170
+ },
171
  ),
172
  ]
173
 
174
+ def _generate_examples(self, annotation, video):
175
  """This function returns the examples in the raw (text) form."""
176
+
177
  pass