nm_marmoset_data / nm_marmoset_data.py
m-vys's picture
Upload folder using huggingface_hub
c708e8c verified
import os
import zipfile
from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Split, Features, Value, BuilderConfig
import shutil
class MarmosetConfig(BuilderConfig):
def __init__(self, unzip_path=None, **kwargs):
super().__init__(**kwargs)
self.unzip_path = unzip_path
class MarmosetData(GeneratorBasedBuilder):
BUILDER_CONFIG_CLASS = MarmosetConfig # 🔑 Tell HF to use your custom config
BUILDER_CONFIGS = [
MarmosetConfig(
name="nm_marmoset_data",
description="Marmoset data unpacker",
)
]
def _info(self):
return DatasetInfo(
description="Unpacks Marmoset natural movie dataset.",
features=Features({
"data_dir": Value("string"), # optional metadata
}),
)
def _split_generators(self, dl_manager):
# Download & extract the needed files
path = 'https://huggingface.co/datasets/m-vys/nm_marmoset_data/resolve/main'
unzip_path = getattr(self.config, 'unzip_path')
urls = {
"stas": os.path.join(path, "stas.zip"),
"responses": os.path.join(path, "responses.zip"),
"fixations": os.path.join(path, "fixations.zip"),
"stimuli_padded": os.path.join(path, "stimuli_padded.zip"),
"stimuli_padded_4": os.path.join(path, "stimuli_padded_4.zip")
}
local_paths = {
name: dl_manager.download_and_extract(url)
for name, url in urls.items()
}
print('local_paths', local_paths)
for name, path in local_paths.items():
src = os.path.join(path, name)
dst = os.path.join(unzip_path, name)
print(f'moving {src} to {dst}')
shutil.move(src, dst)
return [SplitGenerator(name=Split.TRAIN, gen_kwargs={"local_paths": local_paths})]
def _generate_examples(self, local_paths):
#Return a dictionary matching the features
print(" Running _generate_examples with data_dir:", local_paths)
yield 0, {"data_dir": local_paths}