| 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="wn_marmoset_data", |
| description="Marmoset data unpacker", |
| ) |
| ] |
| def _info(self): |
| return DatasetInfo( |
| description="Unpacks Marmoset white noise dataset.", |
| features=Features({ |
| "data_dir": Value("string"), |
| }), |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| |
| path = 'https://huggingface.co/datasets/m-vys/wn_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"), |
| "non_repeating_stimuli_1": os.path.join(path, "non_repeating_stimuli_1.zip"), |
| "non_repeating_stimuli_2": os.path.join(path, "non_repeating_stimuli_2.zip"), |
| "repeating_stimuli_1": os.path.join(path, "repeating_stimuli_1.zip"), |
| "repeating_stimuli_2": os.path.join(path, "repeating_stimuli_2.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} |
|
|
|
|
|
|