mika commited on
Commit
6f375ac
·
1 Parent(s): 26d6282

second commit

Browse files
Files changed (1) hide show
  1. spectrogram_musicCaps.py +114 -0
spectrogram_musicCaps.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+
4
+ # ここに設定を記入
5
+ _NAME = "mickylan2367/spectrogram_musicCaps"
6
+
7
+ # _HOMEPAGE = "https://github.com/fastai/imagenette"
8
+ # プログラムを置く場所が決まったら、ここにホームページURLつける
9
+ _HOMEPAGE = "https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps"
10
+
11
+ _DESCRIPTION = f"""\
12
+ {_NAME} Datasets including spectrogram.png file from Google MusicCaps Datasets!
13
+ Using for Project Learning...
14
+ """
15
+
16
+ # え...なにこれ(;´・ω・)
17
+ _IMAGES_DIR = "mickylan2367/images/"
18
+ # _REPO = "https://huggingface.co/datasets/frgfm/imagenette/resolve/main/metadata"
19
+
20
+
21
+
22
+ class spectrogram_musicCapsConfig(datasets.BuilderConfig):
23
+ """Builder Config for spectrogram_MusicCaps"""
24
+
25
+ def __init__(self, data_url, metadata_urls, **kwargs):
26
+ """BuilderConfig
27
+ Args:
28
+ data_url: `string`, url to download the zip file from.
29
+ metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
30
+ **kwargs: keyword arguments forwarded to super.
31
+ """
32
+ super(spectrogram_musicCapsConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
33
+ self.data_url = data_url
34
+ self.metadata_urls = metadata_urls
35
+
36
+ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
37
+
38
+ # データのサブセットはここで用意
39
+ BUILDER_CONFIGS = [
40
+ spectrogram_musicCapsConfig(
41
+ name="MusicCaps data 0_30",
42
+ description="Datasets from MusicCaps by Mikan",
43
+ data_url="https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data0_50/data0_50.zip",
44
+ metadata_urls={
45
+ "train": "https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data0_50/metadata0_50.jsonl",
46
+ # "validation": "huggingface?"
47
+ },
48
+ ),
49
+ spectrogram_musicCapsConfig(
50
+ name="MusicCpas data 50_80",
51
+ description="Datasets second action by Mikan",
52
+ data_url="https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data50_80/data50_80.zip",
53
+ metadata_urls={
54
+ "train": "https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data50_80/metadata50_80.jsonl",
55
+ # "validation": "https://link-to-dinner-foods-validation.txt"
56
+ },
57
+ )
58
+ ]
59
+
60
+ def _info(self):
61
+ return datasets.DatasetInfo(
62
+ description=_DESCRIPTION,
63
+ features=datasets.Features(
64
+ {
65
+ "image": datasets.Image(),
66
+ "caption": datasets.Value("string")
67
+ }
68
+ ),
69
+ supervised_keys=("image", "caption"),
70
+ homepage=_HOMEPAGE,
71
+ # citation=_CITATION,
72
+ # license=_LICENSE,
73
+ # task_templates=[ImageClassification(image_column="image", label_column="label")],
74
+ )
75
+
76
+ def _split_generators(self, dl_manager):
77
+ archive_path = dl_manager.download(self.config.data_urls)
78
+ split_metadata_paths = dl_manager.download(self.config.metadata_urls)
79
+ return [
80
+ datasets.SplitGenerator(
81
+ name=datasets.Split.TRAIN,
82
+ gen_kwargs={
83
+ "images": dl_manager.iter_archive(archive_path),
84
+ "metadata_path": split_metadata_paths["train"],
85
+ },
86
+ ),
87
+ # datasets.SplitGenerator(
88
+ # name=datasets.Split.VALIDATION,
89
+ # gen_kwargs={
90
+ # "images": dl_manager.iter_archive(archive_path),
91
+ # "metadata_path": split_metadata_paths["test"],
92
+ # },
93
+ # ),
94
+ ]
95
+
96
+ def _generate_examples(self, images, metadata_path):
97
+ """Generate images and captions for splits."""
98
+ with open(metadata_path, encoding="utf-8") as f:
99
+ files_to_keep = set(f.read().split("\n"))
100
+
101
+ for file_path, file_obj in images:
102
+ if file_path.startswith(_IMAGES_DIR):
103
+ if file_path[len(_IMAGES_DIR) : -len(".jpg")] in files_to_keep:
104
+ caption = file_path.split("/")[2]
105
+ # caption = file_path
106
+ yield file_path, {
107
+ "image": {"path": file_path, "bytes": file_obj.read()},
108
+ "caption": caption,
109
+ }
110
+
111
+
112
+
113
+
114
+