Create small.py
Browse files
small.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import json
|
3 |
+
import numpy
|
4 |
+
|
5 |
+
_FEATURES = datasets.Features(
|
6 |
+
{
|
7 |
+
"id": datasets.Value("string"),
|
8 |
+
"prompt": datasets.Array3D(shape=(1, 77, 768), dtype="float32"),
|
9 |
+
"video": datasets.Sequence(feature=datasets.Array3D(shape=(4, 64, 64), dtype="float64")),
|
10 |
+
"description": datasets.Value("string"),
|
11 |
+
"videourl": datasets.Value("string"),
|
12 |
+
"categories": datasets.Value("string"),
|
13 |
+
"duration": datasets.Value("float"),
|
14 |
+
"full_metadata": datasets.Value("string"),
|
15 |
+
}
|
16 |
+
)
|
17 |
+
|
18 |
+
class FunkLoaderStream(datasets.GeneratorBasedBuilder):
|
19 |
+
"""TempoFunk Dataset"""
|
20 |
+
|
21 |
+
def _info(self):
|
22 |
+
return datasets.DatasetInfo(
|
23 |
+
description="TempoFunk Dataset",
|
24 |
+
features=_FEATURES,
|
25 |
+
homepage="None",
|
26 |
+
citation="None",
|
27 |
+
license="None"
|
28 |
+
)
|
29 |
+
|
30 |
+
def _split_generators(self, dl_manager):
|
31 |
+
|
32 |
+
print("id_list available at:", dl_manager.download("data/id_list.json"))
|
33 |
+
|
34 |
+
_ID_LIST = json.loads(open(dl_manager.download("data/id_list.json"), 'r').read())
|
35 |
+
|
36 |
+
_SHARD_LENGTH = 20
|
37 |
+
|
38 |
+
_SPLITS = [_ID_LIST[i:i + _SHARD_LENGTH] for i in range(0, len(_ID_LIST), _SHARD_LENGTH)]
|
39 |
+
|
40 |
+
print("avail splits: ", _SPLITS)
|
41 |
+
|
42 |
+
|
43 |
+
l=[]
|
44 |
+
|
45 |
+
_split_count = 0
|
46 |
+
|
47 |
+
for split in _SPLITS:
|
48 |
+
|
49 |
+
_list = []
|
50 |
+
|
51 |
+
for video_id in split:
|
52 |
+
_list.append({
|
53 |
+
"frames": dl_manager.download(f"data/videos/{video_id}.npy"),
|
54 |
+
"prompt": dl_manager.download(f"data/prompts/{video_id}.npy"),
|
55 |
+
"metadata": dl_manager.download(f"data/metadata/{video_id}.json"),
|
56 |
+
})
|
57 |
+
|
58 |
+
l.append(
|
59 |
+
datasets.SplitGenerator(
|
60 |
+
name=f"split_{_split_count}",
|
61 |
+
gen_kwargs={
|
62 |
+
"chunk_container": _list,
|
63 |
+
},)
|
64 |
+
)
|
65 |
+
|
66 |
+
_split_count = _split_count + 1
|
67 |
+
|
68 |
+
print("Total Splits: ", _split_count)
|
69 |
+
|
70 |
+
return l
|
71 |
+
|
72 |
+
def _generate_examples(self, chunk_container):
|
73 |
+
"""Generate images and labels for splits."""
|
74 |
+
for video_entry in chunk_container:
|
75 |
+
frames_binary = video_entry['frames']
|
76 |
+
prompt_binary = video_entry['prompt']
|
77 |
+
metadata = json.loads(open(video_entry['metadata'], 'r').read())
|
78 |
+
|
79 |
+
txt_embed = numpy.load(prompt_binary)
|
80 |
+
vid_embed = numpy.load(frames_binary)
|
81 |
+
|
82 |
+
print(vid_embed.shape)
|
83 |
+
|
84 |
+
yield metadata['id'], {
|
85 |
+
"id": metadata['id'],
|
86 |
+
"description": metadata['description'],
|
87 |
+
"prompt": txt_embed,
|
88 |
+
"video": vid_embed,
|
89 |
+
"videourl": metadata['videourl'],
|
90 |
+
"categories": metadata['categories'],
|
91 |
+
"duration": metadata['duration'],
|
92 |
+
"full_metadata": metadata
|
93 |
+
}
|