Datasets:
get data from repo
Browse files- ActivityNet_Captions +29 -23
ActivityNet_Captions
CHANGED
@@ -28,6 +28,7 @@ in the paper.
|
|
28 |
|
29 |
_URL_BASE = "https://cs.stanford.edu/people/ranjaykrishna/densevid/"
|
30 |
|
|
|
31 |
|
32 |
class ActivityNetConfig(datasets.BuilderConfig):
|
33 |
"""BuilderConfig for ActivityNet Captions."""
|
@@ -64,13 +65,13 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
|
|
64 |
)
|
65 |
|
66 |
def _split_generators(self, dl_manager):
|
67 |
-
archive_path = dl_manager.
|
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,6 +81,7 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
|
|
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,6 +91,7 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
|
|
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,26 +99,29 @@ class ActivityNet(datasets.GeneratorBasedBuilder):
|
|
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 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
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 |
)
|
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.iterable(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 |
datasets.SplitGenerator(
|
82 |
name=datasets.Split.VALIDATION,
|
83 |
gen_kwargs={
|
84 |
+
"files": dl_manager.iterable(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 |
datasets.SplitGenerator(
|
92 |
name=datasets.Split.TEST,
|
93 |
gen_kwargs={
|
94 |
+
"files": dl_manager.iterable(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 |
]
|
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 |
+
"video_id": datasets.Value("string"),
|
122 |
+
"path": datasets.Value("string"),
|
123 |
+
"duration": infos[id]["duration"],
|
124 |
+
"starts": starts,
|
125 |
+
"ends": ends,
|
126 |
+
"captions": infos[id]["sentences"],
|
127 |
+
}
|