mika commited on
Commit ·
30528a5
1
Parent(s): 6f375ac
loading_script
Browse files- spectrogram_musicCaps.py +34 -36
spectrogram_musicCaps.py
CHANGED
|
@@ -1,29 +1,28 @@
|
|
| 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
|
|
@@ -32,6 +31,9 @@ class spectrogram_musicCapsConfig(datasets.BuilderConfig):
|
|
| 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 |
|
|
@@ -42,7 +44,7 @@ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
|
| 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 |
),
|
|
@@ -51,12 +53,12 @@ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
|
| 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,
|
|
@@ -72,7 +74,7 @@ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
|
| 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)
|
|
@@ -82,33 +84,29 @@ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
|
| 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 |
-
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
import datasets
|
| 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/data/"
|
| 18 |
# _REPO = "https://huggingface.co/datasets/frgfm/imagenette/resolve/main/metadata"
|
| 19 |
|
| 20 |
|
|
|
|
| 21 |
class spectrogram_musicCapsConfig(datasets.BuilderConfig):
|
| 22 |
"""Builder Config for spectrogram_MusicCaps"""
|
| 23 |
+
|
| 24 |
def __init__(self, data_url, metadata_urls, **kwargs):
|
| 25 |
+
"""BuilderConfig
|
| 26 |
Args:
|
| 27 |
data_url: `string`, url to download the zip file from.
|
| 28 |
metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
|
|
|
|
| 31 |
super(spectrogram_musicCapsConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 32 |
self.data_url = data_url
|
| 33 |
self.metadata_urls = metadata_urls
|
| 34 |
+
print(data_url)
|
| 35 |
+
print(metadata_urls)
|
| 36 |
+
|
| 37 |
|
| 38 |
class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
| 39 |
|
|
|
|
| 44 |
description="Datasets from MusicCaps by Mikan",
|
| 45 |
data_url="https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data0_50/data0_50.zip",
|
| 46 |
metadata_urls={
|
| 47 |
+
"train": "https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data0_50/metadata0_50.jsonl",
|
| 48 |
# "validation": "huggingface?"
|
| 49 |
},
|
| 50 |
),
|
|
|
|
| 53 |
description="Datasets second action by Mikan",
|
| 54 |
data_url="https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data50_80/data50_80.zip",
|
| 55 |
metadata_urls={
|
| 56 |
+
"train": "https://huggingface.co/datasets/mickylan2367/spectrogram_musicCaps/blob/main/data/data50_80/metadata50_80.jsonl",
|
| 57 |
# "validation": "https://link-to-dinner-foods-validation.txt"
|
| 58 |
},
|
| 59 |
)
|
| 60 |
]
|
| 61 |
+
|
| 62 |
def _info(self):
|
| 63 |
return datasets.DatasetInfo(
|
| 64 |
description=_DESCRIPTION,
|
|
|
|
| 74 |
# license=_LICENSE,
|
| 75 |
# task_templates=[ImageClassification(image_column="image", label_column="label")],
|
| 76 |
)
|
| 77 |
+
|
| 78 |
def _split_generators(self, dl_manager):
|
| 79 |
archive_path = dl_manager.download(self.config.data_urls)
|
| 80 |
split_metadata_paths = dl_manager.download(self.config.metadata_urls)
|
|
|
|
| 84 |
gen_kwargs={
|
| 85 |
"images": dl_manager.iter_archive(archive_path),
|
| 86 |
"metadata_path": split_metadata_paths["train"],
|
| 87 |
+
}
|
| 88 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
]
|
| 90 |
+
|
| 91 |
def _generate_examples(self, images, metadata_path):
|
| 92 |
+
print(images)
|
| 93 |
"""Generate images and captions for splits."""
|
| 94 |
+
# with open(metadata_path, encoding="utf-8") as f:
|
| 95 |
+
# files_to_keep = set(f.read().split("\n"))
|
| 96 |
with open(metadata_path, encoding="utf-8") as f:
|
| 97 |
+
# テキストファイルの方を入れる..
|
| 98 |
+
captions = f.readlines()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
for idx, (file_path, file_obj) in enumerate(images):
|
| 101 |
+
yield file_path,{
|
| 102 |
+
"image":{"path":file_path, "bytes":file_obj.read()},
|
| 103 |
+
"caption":captions[idx]
|
| 104 |
+
}
|
| 105 |
+
# if file_path.startswith(_IMAGES_DIR): #
|
| 106 |
+
# if file_path[len(_IMAGES_DIR) : -len("*.png")] in files_to_keep:
|
| 107 |
+
# # label = file_path.split("/")[2]
|
| 108 |
+
# caption = captions[idx]
|
| 109 |
+
# yield file_path, {
|
| 110 |
+
# "image": {"path": file_path, "bytes": file_obj.read()},
|
| 111 |
+
# "caption": caption,
|
| 112 |
+
# }
|