| | 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 |
| |
|
| | 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"), |
| | }), |
| | ) |
| |
|
| | def _split_generators(self, dl_manager): |
| | |
| | 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): |
| | |
| | print(" Running _generate_examples with data_dir:", local_paths) |
| | yield 0, {"data_dir": local_paths} |
| |
|
| |
|
| |
|