Leyo commited on
Commit
f73601d
·
1 Parent(s): dc6f97b

try download from original source

Browse files
Files changed (1) hide show
  1. ActivityNet_Captions.py +21 -27
ActivityNet_Captions.py CHANGED
@@ -28,7 +28,6 @@ in the paper.
28
 
29
  _URL_BASE = "https://cs.stanford.edu/people/ranjaykrishna/densevid/"
30
 
31
- _DL_URL = "https://huggingface.co/datasets/Leyo/ActivityNet_Captions/resolve/main/captions.tar.gz"
32
 
33
  class ActivityNetConfig(datasets.BuilderConfig):
34
  """BuilderConfig for ActivityNet Captions."""
@@ -65,13 +64,13 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
65
  )
66
 
67
  def _split_generators(self, dl_manager):
68
- archive_path = dl_manager.download(_DL_URL)
 
69
 
70
  train_splits = [
71
  datasets.SplitGenerator(
72
  name=datasets.Split.TRAIN,
73
  gen_kwargs={
74
- "files": dl_manager.iter_archive(archive_path),
75
  "ids_file": os.path.join(archive_path, "train_ids.json"),
76
  "infos_file": os.path.join(archive_path, "train.json")
77
  },
@@ -81,7 +80,6 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
81
  datasets.SplitGenerator(
82
  name=datasets.Split.VALIDATION,
83
  gen_kwargs={
84
- "files": dl_manager.iter_archive(archive_path),
85
  "ids_file": os.path.join(archive_path, "val_ids.json"),
86
  "infos_file": os.path.join(archive_path, "val_1.json")
87
  },
@@ -91,7 +89,6 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
91
  datasets.SplitGenerator(
92
  name=datasets.Split.TEST,
93
  gen_kwargs={
94
- "files": dl_manager.iter_archive(archive_path),
95
  "ids_file": os.path.join(archive_path, "test_ids.json"),
96
  "infos_file": os.path.join(archive_path, "val_2.json")
97
  },
@@ -99,27 +96,24 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
99
  ]
100
  return train_splits + dev_splits + test_splits
101
 
102
- def _generate_examples(self, files, ids_file, infos_file):
103
  """This function returns the examples."""
104
 
105
- for path, f in files:
106
- if path == infos_file:
107
- with open(f, encoding="utf-8") as json_file:
108
- infos = json.load(json_file)
109
- for path, f in files:
110
- if path == ids_file:
111
- with open(f, encoding="utf-8") as json_file:
112
- ids = json.load(json_file)
113
- for idx, id in enumerate(ids):
114
- path = "https://www.youtube.com/watch?v=" + id[2:]
115
- starts = [timestamp[0]
116
- for timestamp in infos[id]["timestamps"]]
117
- ends = [timestamp[1] for timestamp in infos[id]["timestamps"]]
118
- yield idx, {
119
- "video_id": id,
120
- "path": path,
121
- "duration": infos[id]["duration"],
122
- "starts": starts,
123
- "ends": ends,
124
- "captions": infos[id]["sentences"],
125
- }
 
28
 
29
  _URL_BASE = "https://cs.stanford.edu/people/ranjaykrishna/densevid/"
30
 
 
31
 
32
  class ActivityNetConfig(datasets.BuilderConfig):
33
  """BuilderConfig for ActivityNet Captions."""
 
64
  )
65
 
66
  def _split_generators(self, dl_manager):
67
+ archive_path = dl_manager.download_and_extract(
68
+ _URL_BASE + "captions.zip")
69
 
70
  train_splits = [
71
  datasets.SplitGenerator(
72
  name=datasets.Split.TRAIN,
73
  gen_kwargs={
 
74
  "ids_file": os.path.join(archive_path, "train_ids.json"),
75
  "infos_file": os.path.join(archive_path, "train.json")
76
  },
 
80
  datasets.SplitGenerator(
81
  name=datasets.Split.VALIDATION,
82
  gen_kwargs={
 
83
  "ids_file": os.path.join(archive_path, "val_ids.json"),
84
  "infos_file": os.path.join(archive_path, "val_1.json")
85
  },
 
89
  datasets.SplitGenerator(
90
  name=datasets.Split.TEST,
91
  gen_kwargs={
 
92
  "ids_file": os.path.join(archive_path, "test_ids.json"),
93
  "infos_file": os.path.join(archive_path, "val_2.json")
94
  },
 
96
  ]
97
  return train_splits + dev_splits + test_splits
98
 
99
+ def _generate_examples(self, ids_file, infos_file):
100
  """This function returns the examples."""
101
 
102
+ with open(infos_file, encoding="utf-8") as json_file:
103
+ infos = json.load(json_file)
104
+
105
+ with open(ids_file, encoding="utf-8") as json_file:
106
+ ids = json.load(json_file)
107
+ for idx, id in enumerate(ids):
108
+ path = "https://www.youtube.com/watch?v=" + id[2:]
109
+ starts = [timestamp[0]
110
+ for timestamp in infos[id]["timestamps"]]
111
+ ends = [timestamp[1] for timestamp in infos[id]["timestamps"]]
112
+ yield idx, {
113
+ "video_id": id,
114
+ "path": path,
115
+ "duration": infos[id]["duration"],
116
+ "starts": starts,
117
+ "ends": ends,
118
+ "captions": infos[id]["sentences"],
119
+ }