gorjanradevski commited on
Commit
56299c3
·
verified ·
1 Parent(s): 8b0e939

Upload dave.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. dave.py +45 -50
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
- _CITATION = "" # Optional
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 Dave(datasets.GeneratorBasedBuilder):
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.features.Sequence({
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.features.Sequence(datasets.Value("string")),
50
- "raw_choices_overlayed_full_audio_classification": datasets.features.Sequence(datasets.Value("string")),
51
- "raw_choices_video_segment": datasets.features.Sequence(datasets.Value("string")),
52
- "correct_temporal_order": datasets.features.Sequence(datasets.Value("string")),
53
- "raw_choices_temporal_video": datasets.features.Sequence(datasets.Value("string")),
54
- "raw_choices_multimodal": datasets.features.Sequence(datasets.Value("string")),
55
- "raw_choices_silent_video": datasets.features.Sequence(datasets.Value("string")),
56
- "raw_choices_audio": datasets.features.Sequence(datasets.Value("string")),
57
- "raw_choices_text_only": datasets.features.Sequence(datasets.Value("string")),
58
- "raw_choices_pipeline_event_classification": datasets.features.Sequence(datasets.Value("string")),
59
  }),
60
- supervised_keys=None,
61
  homepage=_HOMEPAGE,
62
  license=_LICENSE,
63
  )
64
 
65
  def _split_generators(self, dl_manager):
66
- json_path = dl_manager.download(_URL)
 
 
 
 
67
 
68
- # Load JSON to collect file URLs
69
- with open(json_path, "r", encoding="utf-8") as f:
70
- data = json.load(f)
71
 
72
- file_urls = set()
73
- for item in data:
74
- for field in _MEDIA_FIELDS:
75
- if field in item:
76
- file_urls.add(item[field])
77
 
78
- # Prefix all file paths with hf:// if they are not already
79
- hf_file_urls = {
80
- f: f.replace("files/", "hf://datasets/gorjanradevski/dave@main/files/")
81
- for f in file_urls
82
- if "P02" in f
83
- }
 
 
 
 
84
 
85
- # Download media files
86
- downloaded_files = dl_manager.download(hf_file_urls)
87
 
88
- return [
89
- datasets.SplitGenerator(
90
- name=datasets.Split.TRAIN,
91
- gen_kwargs={
92
- "json_path": json_path,
93
- "downloaded_files": downloaded_files,
94
- },
 
95
  )
96
- ]
97
 
98
- def _generate_examples(self, json_path, downloaded_files: Dict[str, str]):
 
 
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