Merge branch 'main' of https://huggingface.co/datasets/mickylan2367/LoadingScrptPractice
Browse files
try.py → LoadingScriptPractice.py
RENAMED
|
@@ -32,7 +32,7 @@ Using for Project Learning...
|
|
| 32 |
# https://huggingface.co/docs/datasets/about_dataset_load
|
| 33 |
|
| 34 |
|
| 35 |
-
class
|
| 36 |
"""Builder Config for spectrogram_MusicCaps"""
|
| 37 |
|
| 38 |
def __init__(self, **kwargs):
|
|
@@ -42,23 +42,18 @@ class spectrogram_musicCapsConfig(datasets.BuilderConfig):
|
|
| 42 |
metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
|
| 43 |
**kwargs: keyword arguments forwarded to super.
|
| 44 |
"""
|
| 45 |
-
super(
|
| 46 |
# self.data_url = data_url
|
| 47 |
# self.metadata_urls = metadata_urls
|
| 48 |
|
| 49 |
-
class
|
| 50 |
|
| 51 |
# データのサブセットはここで用意
|
| 52 |
BUILDER_CONFIGS = [
|
| 53 |
-
|
| 54 |
-
name="MusicCaps data
|
| 55 |
-
description="Datasets from MusicCaps
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
# spectrogram_musicCapsConfig(
|
| 59 |
-
# name="MusicCpas data 10_100",
|
| 60 |
-
# description="Datasets second action by Mikan",
|
| 61 |
-
# )
|
| 62 |
]
|
| 63 |
|
| 64 |
def _info(self):
|
|
@@ -104,7 +99,7 @@ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
|
| 104 |
files : zip files
|
| 105 |
'''
|
| 106 |
# リポジトリからダウンロードしてとりあえずキャッシュしたURLリストを取得
|
| 107 |
-
split_metadata_path =
|
| 108 |
downloaded_files_path = dl_manager.download_and_extract(files)
|
| 109 |
|
| 110 |
# 元のコードではzipファイルの中身を"filepath"としてそのまま_generate_exampleに引き渡している?
|
|
@@ -112,14 +107,14 @@ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
|
| 112 |
datasets.SplitGenerator(
|
| 113 |
name = split,
|
| 114 |
gen_kwargs={
|
| 115 |
-
"images" : downloaded_files_path,
|
| 116 |
"metadata_path": split_metadata_path
|
| 117 |
}
|
| 118 |
)
|
| 119 |
)
|
| 120 |
return gs
|
| 121 |
|
| 122 |
-
def _generate_examples(self, images, metadata_path):
|
| 123 |
"""Generate images and captions for splits."""
|
| 124 |
# with open(metadata_path, encoding="utf-8") as f:
|
| 125 |
# files_to_keep = set(f.read().split("\n"))
|
|
@@ -129,7 +124,7 @@ class spectrogram_musicCaps(datasets.GeneratorBasedBuilder):
|
|
| 129 |
num_list = list()
|
| 130 |
label_list = list()
|
| 131 |
|
| 132 |
-
with open(metadata_path) as fin:
|
| 133 |
for line in fin:
|
| 134 |
data = json.loads(line)
|
| 135 |
file_list.append(data["file_name"])
|
|
|
|
| 32 |
# https://huggingface.co/docs/datasets/about_dataset_load
|
| 33 |
|
| 34 |
|
| 35 |
+
class LoadingScriptPracticeConfig(datasets.BuilderConfig):
|
| 36 |
"""Builder Config for spectrogram_MusicCaps"""
|
| 37 |
|
| 38 |
def __init__(self, **kwargs):
|
|
|
|
| 42 |
metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
|
| 43 |
**kwargs: keyword arguments forwarded to super.
|
| 44 |
"""
|
| 45 |
+
super(LoadingScriptPracticeConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 46 |
# self.data_url = data_url
|
| 47 |
# self.metadata_urls = metadata_urls
|
| 48 |
|
| 49 |
+
class LoadingScriptPractice(datasets.GeneratorBasedBuilder):
|
| 50 |
|
| 51 |
# データのサブセットはここで用意
|
| 52 |
BUILDER_CONFIGS = [
|
| 53 |
+
LoadingScriptPracticeConfig(
|
| 54 |
+
name="MusicCaps data 0_3",
|
| 55 |
+
description="this Datasets is personal practice for using loadingScript. Data is from Google/MusicCaps",
|
| 56 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
]
|
| 58 |
|
| 59 |
def _info(self):
|
|
|
|
| 99 |
files : zip files
|
| 100 |
'''
|
| 101 |
# リポジトリからダウンロードしてとりあえずキャッシュしたURLリストを取得
|
| 102 |
+
split_metadata_path = split_metadata_paths[split][0]
|
| 103 |
downloaded_files_path = dl_manager.download_and_extract(files)
|
| 104 |
|
| 105 |
# 元のコードではzipファイルの中身を"filepath"としてそのまま_generate_exampleに引き渡している?
|
|
|
|
| 107 |
datasets.SplitGenerator(
|
| 108 |
name = split,
|
| 109 |
gen_kwargs={
|
| 110 |
+
"images" : dl_manager.iter_archive(downloaded_files_path),
|
| 111 |
"metadata_path": split_metadata_path
|
| 112 |
}
|
| 113 |
)
|
| 114 |
)
|
| 115 |
return gs
|
| 116 |
|
| 117 |
+
def _generate_examples(self, images, metadata_path, dl_manager:DownloadManager):
|
| 118 |
"""Generate images and captions for splits."""
|
| 119 |
# with open(metadata_path, encoding="utf-8") as f:
|
| 120 |
# files_to_keep = set(f.read().split("\n"))
|
|
|
|
| 124 |
num_list = list()
|
| 125 |
label_list = list()
|
| 126 |
|
| 127 |
+
with open(dl_manager.download_and_extract(metadata_path)) as fin:
|
| 128 |
for line in fin:
|
| 129 |
data = json.loads(line)
|
| 130 |
file_list.append(data["file_name"])
|