File size: 2,137 Bytes
c708e8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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}