chavinlo commited on
Commit
5020126
·
1 Parent(s): 614ef05

Create test6.py

Browse files
Files changed (1) hide show
  1. test6.py +85 -0
test6.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import json
3
+ import numpy
4
+ import tarfile
5
+ import io
6
+
7
+ _FEATURES = datasets.Features(
8
+ {
9
+ "id": datasets.Value("string"),
10
+ "prompt": datasets.Array3D(shape=(1, 77, 768), dtype="float32"),
11
+ "video": datasets.Sequence(feature=datasets.Array3D(shape=(4, 64, 64), dtype="float32")),
12
+ "description": datasets.Value("string"),
13
+ "videourl": datasets.Value("string"),
14
+ "categories": datasets.Value("string"),
15
+ "duration": datasets.Value("float"),
16
+ "full_metadata": datasets.Value("string"),
17
+ }
18
+ )
19
+
20
+ class FunkLoaderStream(datasets.GeneratorBasedBuilder):
21
+ """TempoFunk Dataset"""
22
+
23
+ def _info(self):
24
+ return datasets.DatasetInfo(
25
+ description="TempoFunk Dataset",
26
+ features=_FEATURES,
27
+ homepage="None",
28
+ citation="None",
29
+ license="None"
30
+ )
31
+
32
+ def _split_generators(self, dl_manager):
33
+ # Load the chunk list.
34
+ _CHUNK_LIST = json.loads(open(dl_manager.download("lists/chunk_list.json"), 'r').read())
35
+
36
+ # Create a list to hold the downloaded chunks.
37
+ _list = []
38
+
39
+ # Download each chunk file.
40
+ for chunk in _CHUNK_LIST:
41
+ _list.append(dl_manager.download(f"data/{chunk}.tar"))
42
+
43
+ # Return the list of downloaded chunks.
44
+ return [
45
+ datasets.SplitGenerator(
46
+ name=datasets.Split.TRAIN,
47
+ gen_kwargs={
48
+ "chunks": _list,
49
+ },
50
+ ),
51
+ ]
52
+
53
+ def _generate_examples(self, chunks):
54
+ """Generate images and labels for splits."""
55
+ for chunk in chunks:
56
+ tar_data = open(chunk, 'rb')
57
+ tar_bytes = tar_data.read()
58
+ tar_bytes_io = io.BytesIO(tar_bytes)
59
+
60
+ response_dict = {}
61
+
62
+ with tarfile.open(fileobj=tar_bytes_io, mode='r') as tar:
63
+ for file_info in tar:
64
+ if file_info.isfile():
65
+ file_name = file_info.name
66
+ #filename format is typ_id.ext
67
+ file_type = file_name.split('_')[0]
68
+ file_id = file_name.split('_')[1].split('.')[0]
69
+ file_ext = file_name.split('_')[1].split('.')[1]
70
+ file_contents = tar.extractfile(file_info).read()
71
+
72
+ # vis = video std; vim = video mean
73
+ if file_type == 'txt' or file_type == 'vis' or file_type == 'vim':
74
+ response_dict[file_id][file_type] = numpy.load(file_contents)
75
+ elif file_type == 'jso':
76
+ response_dict[file_id][file_type] = json.loads(file_contents)
77
+
78
+ for key, value in response_dict.items():
79
+ yield key, {
80
+ "id": key,
81
+ "metadata": value['jso'],
82
+ "prompt": value['txt'],
83
+ "vidmean": value['vim'],
84
+ "vidstd": value['vis'],
85
+ }