File size: 2,707 Bytes
8a854e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423f06c
 
d7d87bd
d95b791
d7d87bd
 
 
 
487e311
 
 
 
 
 
 
8a854e6
 
c87347e
c8f23b2
c87347e
 
 
 
4e58da6
bf5b05a
c87347e
 
 
 
 
 
 
 
553a8ca
42265f2
 
17202fc
42265f2
423f06c
42265f2
bf5b05a
487e311
d7d87bd
42265f2
487e311
42265f2
 
487e311
42265f2
 
 
 
aa5ff82
0f01563
e5a2db9
5e734f6
42265f2
90ae1fc
42265f2
 
 
 
90ae1fc
42265f2
 
 
90ae1fc
 
42265f2
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import datasets
import urllib.request
import csv

_CITATION = """\
@InProceedings{huggingface:dataset,
title = {diffusion train set},
}
"""

_DESCRIPTION = """\
This is a dataset that image data and caption txt
"""
_HOMEPAGE = ""

_LICENSE = ""

_VERSION = "0.0.1"

_URL = "data/"
   
_URLS = {        
            "train": _URL + 'train1_dataset.csv',
            "reg": _URL + 'reg1_dataset.csv',
            }
task_list = [
    "train",
    "reg",
]
class taskConfig(datasets.BuilderConfig):
    def __init__(self, **kwargs):
        super().__init__(version=datasets.Version("1.0.0"), **kwargs)

class imgdataset(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        taskConfig(
            name=task_name,
        )
        for task_name in task_list
    ]
    
    def _info(self):
        features = datasets.Features(
            {
                "folder_name" : datasets.Value("string"),
                "Class_name": datasets.Value("string"),
                "file_name": datasets.Value("string"),
                "file_id": datasets.Value("string")
        
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=None,
            version=_VERSION,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager):
        downloaded_files = dl_manager.download_and_extract(_URLS)
        task_name = self.config.name
        return [
            datasets.SplitGenerator(datasets.Split.TRAIN, {
                "filepath": downloaded_files[task_name]
            }),
            ]
    def _generate_examples(self, filepath):
        """This function returns the examples in the raw (text) form."""
        with open(filepath, encoding="utf-8") as f:
            data = csv.DictReader(f)
            key = 0
            for row in data:
                yield key, {
                    "folder_name" : row['folder_name'],
                    "Class_name": row['Class_name'],
                    "file_name": row['file_name'],
                    "file_id": row['file_id']
                }
                folder_name = row['folder_name']
                class_name =row['Class_name']
                file_name = row['file_name']
                url =row['file_id']
                path = os.path.join('./',folder_name,class_name,file_name)
                folder = os.path.join('./',folder_name,class_name)
                if not os.path.isdir(folder): #폴더가 존재하지 않는다면 폴더 생성
                    os.makedirs(folder)
                urllib.request.urlretrieve(url, path)
                key += 1