chavinlo commited on
Commit
650d521
1 Parent(s): 1ce35fe

Upload tempofunk-s.py

Browse files
Files changed (1) hide show
  1. tempofunk-s.py +96 -0
tempofunk-s.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # txt_embed = torch.load(open(prompt_binary, 'rb')).cpu().detach().numpy()
83
+ # vid_embed = torch.load(open(frames_binary, 'rb'))
84
+
85
+ print(vid_embed.shape)
86
+
87
+ yield metadata['id'], {
88
+ "id": metadata['id'],
89
+ "prompt": txt_embed,
90
+ "video": vid_embed,
91
+ "description": metadata['description'],
92
+ "videourl": metadata['videourl'],
93
+ "categories": metadata['categories'],
94
+ "duration": metadata['duration'],
95
+ "full_metadata": metadata
96
+ }