Create big.py
Browse files
big.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
import json
|
| 3 |
+
import numpy
|
| 4 |
+
import tarfile
|
| 5 |
+
import io
|
| 6 |
+
from io import BytesIO
|
| 7 |
+
|
| 8 |
+
_FEATURES = datasets.Features(
|
| 9 |
+
{
|
| 10 |
+
"id": datasets.Value("string"),
|
| 11 |
+
"metadata": datasets.Value("string"),
|
| 12 |
+
"prompt": datasets.Array3D(shape=(1, 77, 768), dtype="float32"),
|
| 13 |
+
"vidmean": datasets.Sequence(feature=datasets.Array3D(shape=(4, 64, 64), dtype="float32")),
|
| 14 |
+
"vidstd": datasets.Sequence(feature=datasets.Array3D(shape=(4, 64, 64), dtype="float32"))
|
| 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 |
+
# Load the chunk list.
|
| 32 |
+
_CHUNK_LIST = json.loads(open(dl_manager.download("lists/chunk_list.json"), 'r').read())
|
| 33 |
+
|
| 34 |
+
# Create a list to hold the downloaded chunks.
|
| 35 |
+
_list = []
|
| 36 |
+
|
| 37 |
+
# Download each chunk file.
|
| 38 |
+
for chunk in _CHUNK_LIST:
|
| 39 |
+
_list.append(dl_manager.download(f"data/{chunk}.tar"))
|
| 40 |
+
|
| 41 |
+
# Return the list of downloaded chunks.
|
| 42 |
+
return [
|
| 43 |
+
datasets.SplitGenerator(
|
| 44 |
+
name=datasets.Split.TRAIN,
|
| 45 |
+
gen_kwargs={
|
| 46 |
+
"chunks": _list,
|
| 47 |
+
},
|
| 48 |
+
),
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
def _generate_examples(self, chunks):
|
| 52 |
+
"""Generate images and labels for splits."""
|
| 53 |
+
for chunk in chunks:
|
| 54 |
+
tar_data = open(chunk, 'rb')
|
| 55 |
+
tar_bytes = tar_data.read()
|
| 56 |
+
tar_bytes_io = io.BytesIO(tar_bytes)
|
| 57 |
+
|
| 58 |
+
response_dict = {}
|
| 59 |
+
|
| 60 |
+
with tarfile.open(fileobj=tar_bytes_io, mode='r') as tar:
|
| 61 |
+
for file_info in tar:
|
| 62 |
+
if file_info.isfile():
|
| 63 |
+
file_name = file_info.name
|
| 64 |
+
#filename format is typ_id.ext
|
| 65 |
+
file_type = file_name.split('_')[0]
|
| 66 |
+
file_id = file_name.split('_')[1].split('.')[0]
|
| 67 |
+
file_ext = file_name.split('_')[1].split('.')[1]
|
| 68 |
+
file_contents = tar.extractfile(file_info)
|
| 69 |
+
|
| 70 |
+
if file_id not in response_dict:
|
| 71 |
+
response_dict[file_id] = {}
|
| 72 |
+
|
| 73 |
+
# vis = video std; vim = video mean
|
| 74 |
+
if file_type == 'txt' or file_type == 'vis' or file_type == 'vim':
|
| 75 |
+
#don't ask me why, it just works
|
| 76 |
+
_tmp = BytesIO()
|
| 77 |
+
_tmp.write(tar.extractfile(file_name).read())
|
| 78 |
+
_tmp.seek(0)
|
| 79 |
+
file_contents = _tmp
|
| 80 |
+
response_dict[file_id][file_type] = numpy.load(file_contents)
|
| 81 |
+
elif file_type == 'jso':
|
| 82 |
+
response_dict[file_id][file_type] = json.loads(file_contents.read())
|
| 83 |
+
|
| 84 |
+
for key, value in response_dict.items():
|
| 85 |
+
yield key, {
|
| 86 |
+
"id": key,
|
| 87 |
+
"metadata": json.dumps(value['jso']),
|
| 88 |
+
"prompt": value['txt'],
|
| 89 |
+
"vidmean": value['vim'],
|
| 90 |
+
"vidstd": value['vis'],
|
| 91 |
+
}
|