Upload dave.py with huggingface_hub
Browse files
dave.py
CHANGED
@@ -1,17 +1,11 @@
|
|
1 |
import json
|
2 |
-
import os
|
3 |
-
from pathlib import Path
|
4 |
-
from typing import Dict, List, Tuple
|
5 |
|
6 |
import datasets
|
7 |
|
8 |
-
|
9 |
-
_DESCRIPTION = "A multimodal dataset including video/audio and rich annotations."
|
10 |
_HOMEPAGE = "https://huggingface.co/datasets/gorjanradevski/dave"
|
11 |
_LICENSE = "MIT"
|
12 |
-
_URL = "https://huggingface.co/datasets/gorjanradevski/dave/resolve/main/epic.json"
|
13 |
|
14 |
-
# These fields contain file references
|
15 |
_MEDIA_FIELDS = [
|
16 |
"raw_video_path",
|
17 |
"compressed_video_path",
|
@@ -21,9 +15,7 @@ _MEDIA_FIELDS = [
|
|
21 |
"overlayed_audio_path",
|
22 |
]
|
23 |
|
24 |
-
class
|
25 |
-
VERSION = datasets.Version("1.0.0")
|
26 |
-
|
27 |
def _info(self):
|
28 |
return datasets.DatasetInfo(
|
29 |
description=_DESCRIPTION,
|
@@ -31,7 +23,7 @@ class Dave(datasets.GeneratorBasedBuilder):
|
|
31 |
"raw_video_path": datasets.Value("string"),
|
32 |
"compressed_video_path": datasets.Value("string"),
|
33 |
"overlayed_event_index": datasets.Value("int32"),
|
34 |
-
"events": datasets.
|
35 |
"start": datasets.Value("string"),
|
36 |
"end": datasets.Value("string"),
|
37 |
"duration": datasets.Value("float64"),
|
@@ -46,64 +38,67 @@ class Dave(datasets.GeneratorBasedBuilder):
|
|
46 |
"video_id": datasets.Value("string"),
|
47 |
"participant_id": datasets.Value("string"),
|
48 |
"type": datasets.Value("string"),
|
49 |
-
"raw_choices_simple_audio_classification": datasets.
|
50 |
-
"raw_choices_overlayed_full_audio_classification": datasets.
|
51 |
-
"raw_choices_video_segment": datasets.
|
52 |
-
"correct_temporal_order": datasets.
|
53 |
-
"raw_choices_temporal_video": datasets.
|
54 |
-
"raw_choices_multimodal": datasets.
|
55 |
-
"raw_choices_silent_video": datasets.
|
56 |
-
"raw_choices_audio": datasets.
|
57 |
-
"raw_choices_text_only": datasets.
|
58 |
-
"raw_choices_pipeline_event_classification": datasets.
|
59 |
}),
|
60 |
-
supervised_keys=None,
|
61 |
homepage=_HOMEPAGE,
|
62 |
license=_LICENSE,
|
63 |
)
|
64 |
|
65 |
def _split_generators(self, dl_manager):
|
66 |
-
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
for field in _MEDIA_FIELDS:
|
75 |
-
if field in item:
|
76 |
-
file_urls.add(item[field])
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
downloaded_files = dl_manager.download(hf_file_urls)
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
95 |
)
|
96 |
-
]
|
97 |
|
98 |
-
|
|
|
|
|
99 |
with open(json_path, "r", encoding="utf-8") as f:
|
100 |
data = json.load(f)
|
101 |
|
102 |
for idx, item in enumerate(data):
|
103 |
-
# Replace file references with local downloaded paths
|
104 |
for field in _MEDIA_FIELDS:
|
105 |
if field in item and item[field] in downloaded_files:
|
106 |
item[field] = downloaded_files[item[field]]
|
107 |
|
108 |
yield idx, item
|
109 |
-
|
|
|
1 |
import json
|
|
|
|
|
|
|
2 |
|
3 |
import datasets
|
4 |
|
5 |
+
_DESCRIPTION = "Dataset with video and audio references for epic and ego4d tasks."
|
|
|
6 |
_HOMEPAGE = "https://huggingface.co/datasets/gorjanradevski/dave"
|
7 |
_LICENSE = "MIT"
|
|
|
8 |
|
|
|
9 |
_MEDIA_FIELDS = [
|
10 |
"raw_video_path",
|
11 |
"compressed_video_path",
|
|
|
15 |
"overlayed_audio_path",
|
16 |
]
|
17 |
|
18 |
+
class DaveDataset(datasets.GeneratorBasedBuilder):
|
|
|
|
|
19 |
def _info(self):
|
20 |
return datasets.DatasetInfo(
|
21 |
description=_DESCRIPTION,
|
|
|
23 |
"raw_video_path": datasets.Value("string"),
|
24 |
"compressed_video_path": datasets.Value("string"),
|
25 |
"overlayed_event_index": datasets.Value("int32"),
|
26 |
+
"events": datasets.Sequence({
|
27 |
"start": datasets.Value("string"),
|
28 |
"end": datasets.Value("string"),
|
29 |
"duration": datasets.Value("float64"),
|
|
|
38 |
"video_id": datasets.Value("string"),
|
39 |
"participant_id": datasets.Value("string"),
|
40 |
"type": datasets.Value("string"),
|
41 |
+
"raw_choices_simple_audio_classification": datasets.Sequence(datasets.Value("string")),
|
42 |
+
"raw_choices_overlayed_full_audio_classification": datasets.Sequence(datasets.Value("string")),
|
43 |
+
"raw_choices_video_segment": datasets.Sequence(datasets.Value("string")),
|
44 |
+
"correct_temporal_order": datasets.Sequence(datasets.Value("string")),
|
45 |
+
"raw_choices_temporal_video": datasets.Sequence(datasets.Value("string")),
|
46 |
+
"raw_choices_multimodal": datasets.Sequence(datasets.Value("string")),
|
47 |
+
"raw_choices_silent_video": datasets.Sequence(datasets.Value("string")),
|
48 |
+
"raw_choices_audio": datasets.Sequence(datasets.Value("string")),
|
49 |
+
"raw_choices_text_only": datasets.Sequence(datasets.Value("string")),
|
50 |
+
"raw_choices_pipeline_event_classification": datasets.Sequence(datasets.Value("string")),
|
51 |
}),
|
|
|
52 |
homepage=_HOMEPAGE,
|
53 |
license=_LICENSE,
|
54 |
)
|
55 |
|
56 |
def _split_generators(self, dl_manager):
|
57 |
+
base_url = "https://huggingface.co/datasets/gorjanradevski/dave/resolve/main/"
|
58 |
+
json_files = {
|
59 |
+
"epic": "epic.json",
|
60 |
+
"ego4d": "ego4d.json"
|
61 |
+
}
|
62 |
|
63 |
+
split_generators = []
|
64 |
+
for split_name, json_file in json_files.items():
|
65 |
+
json_path = dl_manager.download(base_url + json_file)
|
66 |
|
67 |
+
with open(json_path, "r", encoding="utf-8") as f:
|
68 |
+
data = json.load(f)
|
|
|
|
|
|
|
69 |
|
70 |
+
file_paths = set()
|
71 |
+
for item in data:
|
72 |
+
for field in _MEDIA_FIELDS:
|
73 |
+
if field in item:
|
74 |
+
file_paths.add(item[field])
|
75 |
+
|
76 |
+
hf_file_urls = {
|
77 |
+
f: f.replace("files/", "hf://datasets/gorjanradevski/dave@main/files/")
|
78 |
+
for f in file_paths
|
79 |
+
}
|
80 |
|
81 |
+
downloaded_files = dl_manager.download(hf_file_urls)
|
|
|
82 |
|
83 |
+
split_generators.append(
|
84 |
+
datasets.SplitGenerator(
|
85 |
+
name=split_name,
|
86 |
+
gen_kwargs={
|
87 |
+
"json_path": json_path,
|
88 |
+
"downloaded_files": downloaded_files,
|
89 |
+
},
|
90 |
+
)
|
91 |
)
|
|
|
92 |
|
93 |
+
return split_generators
|
94 |
+
|
95 |
+
def _generate_examples(self, json_path, downloaded_files):
|
96 |
with open(json_path, "r", encoding="utf-8") as f:
|
97 |
data = json.load(f)
|
98 |
|
99 |
for idx, item in enumerate(data):
|
|
|
100 |
for field in _MEDIA_FIELDS:
|
101 |
if field in item and item[field] in downloaded_files:
|
102 |
item[field] = downloaded_files[item[field]]
|
103 |
|
104 |
yield idx, item
|
|