| # Uploaded at: https://huggingface.co/datasets/hkamath-rudra/fma | |
| # To use: | |
| # from datasets import load_dataset | |
| # dataset = load_dataset("hkamath-rudra/fma", "small", streaming=True) | |
| dataset_links = { | |
| "metadata": "https://os.unil.cloud.switch.ch/fma/fma_metadata.zip", | |
| "small": "https://os.unil.cloud.switch.ch/fma/fma_small.zip", | |
| "medium": "https://os.unil.cloud.switch.ch/fma/fma_medium.zip", | |
| "large": "https://os.unil.cloud.switch.ch/fma/fma_large.zip", | |
| "full": "https://os.unil.cloud.switch.ch/fma/fma_full.zip", | |
| } | |
| requirements = """ | |
| cachetools==5.2.1 | |
| certifi==2022.6.15 | |
| charset-normalizer==2.1.1 | |
| einops==0.4.1 | |
| idna==3.3 | |
| protobuf==4.21.12 | |
| pyasn1==0.4.8 | |
| pyasn1-modules==0.2.8 | |
| python-dateutil==2.8.2 | |
| pytz==2022.2.1 | |
| requests==2.28.1 | |
| rsa==4.9 | |
| six==1.16.0 | |
| tqdm==4.64.1 | |
| typing_extensions==4.3.0 | |
| urllib3==1.26.12 | |
| datasets | |
| pandas | |
| """.strip().split( | |
| "\n" | |
| ) | |
| import io | |
| def utils_load(filepath: str, file: io.BufferedReader = None): | |
| """Helper function from fma github: https://github.com/mdeff/fma""" | |
| import pandas as pd | |
| import os | |
| import ast | |
| filename = os.path.basename(filepath) | |
| if "features" in filename: | |
| return pd.read_csv(file, index_col=0, header=[0, 1, 2]) | |
| if "echonest" in filename: | |
| return pd.read_csv(file, index_col=0, header=[0, 1, 2]) | |
| if "genres" in filename: | |
| return pd.read_csv(file, index_col=0) | |
| if "tracks" in filename: | |
| tracks = pd.read_csv(file, index_col=0, header=[0, 1]) | |
| COLUMNS = [ | |
| ("track", "tags"), | |
| ("album", "tags"), | |
| ("artist", "tags"), | |
| ("track", "genres"), | |
| ("track", "genres_all"), | |
| ] | |
| for column in COLUMNS: | |
| tracks[column] = tracks[column].map(ast.literal_eval) | |
| COLUMNS = [ | |
| ("track", "date_created"), | |
| ("track", "date_recorded"), | |
| ("album", "date_created"), | |
| ("album", "date_released"), | |
| ("artist", "date_created"), | |
| ("artist", "active_year_begin"), | |
| ("artist", "active_year_end"), | |
| ] | |
| for column in COLUMNS: | |
| tracks[column] = pd.to_datetime(tracks[column]) | |
| SUBSETS = ("small", "medium", "large") | |
| try: | |
| tracks["set", "subset"] = tracks["set", "subset"].astype("category", categories=SUBSETS, ordered=True) | |
| except (ValueError, TypeError): | |
| # the categories and ordered arguments were removed in pandas 0.25 | |
| tracks["set", "subset"] = tracks["set", "subset"].astype( | |
| pd.CategoricalDtype(categories=SUBSETS, ordered=True) | |
| ) | |
| COLUMNS = [ | |
| ("track", "genre_top"), | |
| ("track", "license"), | |
| ("album", "type"), | |
| ("album", "information"), | |
| ("artist", "bio"), | |
| ] | |
| for column in COLUMNS: | |
| tracks[column] = tracks[column].astype("category") | |
| return tracks | |
| import pandas as pd | |
| def read_metadata( | |
| tracks_df: pd.DataFrame, | |
| genres_df: pd.DataFrame = None, | |
| features_df: pd.DataFrame = None, | |
| echonest_df: pd.DataFrame = None, | |
| ): | |
| import os | |
| import pandas as pd | |
| import time | |
| from dataclasses import dataclass | |
| class Metadata: | |
| tracks: pd.DataFrame | |
| genres: pd.DataFrame = None | |
| features: pd.DataFrame = None | |
| echonest: pd.DataFrame = None | |
| return Metadata( | |
| tracks_df.set_axis(tracks_df.columns.map(".".join), axis=1), | |
| genres_df, | |
| features_df.set_axis(features_df.columns.map(".".join), axis=1) if features_df is not None else None, | |
| echonest_df.set_axis(echonest_df.columns.map(".".join), axis=1) if echonest_df is not None else None, | |
| ) | |
| import datasets | |
| _CITATION = """""" | |
| _DESCRIPTION = """ | |
| FMA is a dataset for music analysis. It includes song title, album, artist, genres; spectrograms, metadata, and features. | |
| """ | |
| _HOMEPAGE = "http://freemusicarchive.org/" | |
| _LICENSE = "" | |
| # Have to do it this way bc otherwise, you would need to load metadata before _split_generators | |
| METADATA_FIELDS = { | |
| # Tracks | |
| "album.comments": "int64", | |
| "album.date_created": "datetime64[ns]", | |
| "album.date_released": "datetime64[ns]", | |
| "album.engineer": "object", | |
| "album.favorites": "int64", | |
| "album.id": "int64", | |
| "album.information": "category", | |
| "album.listens": "int64", | |
| "album.producer": "object", | |
| "album.tags": "object", | |
| "album.title": "object", | |
| "album.tracks": "int64", | |
| "album.type": "category", | |
| "artist.active_year_begin": "datetime64[ns]", | |
| "artist.active_year_end": "datetime64[ns]", | |
| "artist.associated_labels": "object", | |
| "artist.bio": "category", | |
| "artist.comments": "int64", | |
| "artist.date_created": "datetime64[ns]", | |
| "artist.favorites": "int64", | |
| "artist.id": "int64", | |
| "artist.latitude": "float64", | |
| "artist.location": "object", | |
| "artist.longitude": "float64", | |
| "artist.members": "object", | |
| "artist.name": "object", | |
| "artist.related_projects": "object", | |
| "artist.tags": "object", | |
| "artist.website": "object", | |
| "artist.wikipedia_page": "object", | |
| "set.split": "object", | |
| "set.subset": "category", | |
| "track.bit_rate": "int64", | |
| "track.comments": "int64", | |
| "track.composer": "object", | |
| "track.date_created": "datetime64[ns]", | |
| "track.date_recorded": "datetime64[ns]", | |
| "track.duration": "int64", | |
| "track.favorites": "int64", | |
| "track.genre_top": "category", | |
| "track.genres": "object", | |
| "track.genres_all": "object", | |
| "track.information": "object", | |
| "track.interest": "int64", | |
| "track.language_code": "object", | |
| "track.license": "category", | |
| "track.listens": "int64", | |
| "track.lyricist": "object", | |
| "track.number": "int64", | |
| "track.publisher": "object", | |
| "track.tags": "object", | |
| "track.title": "object", | |
| # Features | |
| # "chroma_cens.kurtosis.01": "float64", | |
| # "chroma_cens.kurtosis.02": "float64", | |
| # "chroma_cens.kurtosis.03": "float64", | |
| # "chroma_cens.kurtosis.04": "float64", | |
| # "chroma_cens.kurtosis.05": "float64", | |
| # "chroma_cens.kurtosis.06": "float64", | |
| # "chroma_cens.kurtosis.07": "float64", | |
| # "chroma_cens.kurtosis.08": "float64", | |
| # "chroma_cens.kurtosis.09": "float64", | |
| # "chroma_cens.kurtosis.10": "float64", | |
| # "chroma_cens.kurtosis.11": "float64", | |
| # "chroma_cens.kurtosis.12": "float64", | |
| # "chroma_cens.max.01": "float64", | |
| # "chroma_cens.max.02": "float64", | |
| # "chroma_cens.max.03": "float64", | |
| # "chroma_cens.max.04": "float64", | |
| # "chroma_cens.max.05": "float64", | |
| # "chroma_cens.max.06": "float64", | |
| # "chroma_cens.max.07": "float64", | |
| # "chroma_cens.max.08": "float64", | |
| # "chroma_cens.max.09": "float64", | |
| # "chroma_cens.max.10": "float64", | |
| # "chroma_cens.max.11": "float64", | |
| # "chroma_cens.max.12": "float64", | |
| # "chroma_cens.mean.01": "float64", | |
| # "chroma_cens.mean.02": "float64", | |
| # "chroma_cens.mean.03": "float64", | |
| # "chroma_cens.mean.04": "float64", | |
| # "chroma_cens.mean.05": "float64", | |
| # "chroma_cens.mean.06": "float64", | |
| # "chroma_cens.mean.07": "float64", | |
| # "chroma_cens.mean.08": "float64", | |
| # "chroma_cens.mean.09": "float64", | |
| # "chroma_cens.mean.10": "float64", | |
| # "chroma_cens.mean.11": "float64", | |
| # "chroma_cens.mean.12": "float64", | |
| # "chroma_cens.median.01": "float64", | |
| # "chroma_cens.median.02": "float64", | |
| # "chroma_cens.median.03": "float64", | |
| # "chroma_cens.median.04": "float64", | |
| # "chroma_cens.median.05": "float64", | |
| # "chroma_cens.median.06": "float64", | |
| # "chroma_cens.median.07": "float64", | |
| # "chroma_cens.median.08": "float64", | |
| # "chroma_cens.median.09": "float64", | |
| # "chroma_cens.median.10": "float64", | |
| # "chroma_cens.median.11": "float64", | |
| # "chroma_cens.median.12": "float64", | |
| # "chroma_cens.min.01": "float64", | |
| # "chroma_cens.min.02": "float64", | |
| # "chroma_cens.min.03": "float64", | |
| # "chroma_cens.min.04": "float64", | |
| # "chroma_cens.min.05": "float64", | |
| # "chroma_cens.min.06": "float64", | |
| # "chroma_cens.min.07": "float64", | |
| # "chroma_cens.min.08": "float64", | |
| # "chroma_cens.min.09": "float64", | |
| # "chroma_cens.min.10": "float64", | |
| # "chroma_cens.min.11": "float64", | |
| # "chroma_cens.min.12": "float64", | |
| # "chroma_cens.skew.01": "float64", | |
| # "chroma_cens.skew.02": "float64", | |
| # "chroma_cens.skew.03": "float64", | |
| # "chroma_cens.skew.04": "float64", | |
| # "chroma_cens.skew.05": "float64", | |
| # "chroma_cens.skew.06": "float64", | |
| # "chroma_cens.skew.07": "float64", | |
| # "chroma_cens.skew.08": "float64", | |
| # "chroma_cens.skew.09": "float64", | |
| # "chroma_cens.skew.10": "float64", | |
| # "chroma_cens.skew.11": "float64", | |
| # "chroma_cens.skew.12": "float64", | |
| # "chroma_cens.std.01": "float64", | |
| # "chroma_cens.std.02": "float64", | |
| # "chroma_cens.std.03": "float64", | |
| # "chroma_cens.std.04": "float64", | |
| # "chroma_cens.std.05": "float64", | |
| # "chroma_cens.std.06": "float64", | |
| # "chroma_cens.std.07": "float64", | |
| # "chroma_cens.std.08": "float64", | |
| # "chroma_cens.std.09": "float64", | |
| # "chroma_cens.std.10": "float64", | |
| # "chroma_cens.std.11": "float64", | |
| # "chroma_cens.std.12": "float64", | |
| # "chroma_cqt.kurtosis.01": "float64", | |
| # "chroma_cqt.kurtosis.02": "float64", | |
| # "chroma_cqt.kurtosis.03": "float64", | |
| # "chroma_cqt.kurtosis.04": "float64", | |
| # "chroma_cqt.kurtosis.05": "float64", | |
| # "chroma_cqt.kurtosis.06": "float64", | |
| # "chroma_cqt.kurtosis.07": "float64", | |
| # "chroma_cqt.kurtosis.08": "float64", | |
| # "chroma_cqt.kurtosis.09": "float64", | |
| # "chroma_cqt.kurtosis.10": "float64", | |
| # "chroma_cqt.kurtosis.11": "float64", | |
| # "chroma_cqt.kurtosis.12": "float64", | |
| # "chroma_cqt.max.01": "float64", | |
| # "chroma_cqt.max.02": "float64", | |
| # "chroma_cqt.max.03": "float64", | |
| # "chroma_cqt.max.04": "float64", | |
| # "chroma_cqt.max.05": "float64", | |
| # "chroma_cqt.max.06": "float64", | |
| # "chroma_cqt.max.07": "float64", | |
| # "chroma_cqt.max.08": "float64", | |
| # "chroma_cqt.max.09": "float64", | |
| # "chroma_cqt.max.10": "float64", | |
| # "chroma_cqt.max.11": "float64", | |
| # "chroma_cqt.max.12": "float64", | |
| # "chroma_cqt.mean.01": "float64", | |
| # "chroma_cqt.mean.02": "float64", | |
| # "chroma_cqt.mean.03": "float64", | |
| # "chroma_cqt.mean.04": "float64", | |
| # "chroma_cqt.mean.05": "float64", | |
| # "chroma_cqt.mean.06": "float64", | |
| # "chroma_cqt.mean.07": "float64", | |
| # "chroma_cqt.mean.08": "float64", | |
| # "chroma_cqt.mean.09": "float64", | |
| # "chroma_cqt.mean.10": "float64", | |
| # "chroma_cqt.mean.11": "float64", | |
| # "chroma_cqt.mean.12": "float64", | |
| # "chroma_cqt.median.01": "float64", | |
| # "chroma_cqt.median.02": "float64", | |
| # "chroma_cqt.median.03": "float64", | |
| # "chroma_cqt.median.04": "float64", | |
| # "chroma_cqt.median.05": "float64", | |
| # "chroma_cqt.median.06": "float64", | |
| # "chroma_cqt.median.07": "float64", | |
| # "chroma_cqt.median.08": "float64", | |
| # "chroma_cqt.median.09": "float64", | |
| # "chroma_cqt.median.10": "float64", | |
| # "chroma_cqt.median.11": "float64", | |
| # "chroma_cqt.median.12": "float64", | |
| # "chroma_cqt.min.01": "float64", | |
| # "chroma_cqt.min.02": "float64", | |
| # "chroma_cqt.min.03": "float64", | |
| # "chroma_cqt.min.04": "float64", | |
| # "chroma_cqt.min.05": "float64", | |
| # "chroma_cqt.min.06": "float64", | |
| # "chroma_cqt.min.07": "float64", | |
| # "chroma_cqt.min.08": "float64", | |
| # "chroma_cqt.min.09": "float64", | |
| # "chroma_cqt.min.10": "float64", | |
| # "chroma_cqt.min.11": "float64", | |
| # "chroma_cqt.min.12": "float64", | |
| # "chroma_cqt.skew.01": "float64", | |
| # "chroma_cqt.skew.02": "float64", | |
| # "chroma_cqt.skew.03": "float64", | |
| # "chroma_cqt.skew.04": "float64", | |
| # "chroma_cqt.skew.05": "float64", | |
| # "chroma_cqt.skew.06": "float64", | |
| # "chroma_cqt.skew.07": "float64", | |
| # "chroma_cqt.skew.08": "float64", | |
| # "chroma_cqt.skew.09": "float64", | |
| # "chroma_cqt.skew.10": "float64", | |
| # "chroma_cqt.skew.11": "float64", | |
| # "chroma_cqt.skew.12": "float64", | |
| # "chroma_cqt.std.01": "float64", | |
| # "chroma_cqt.std.02": "float64", | |
| # "chroma_cqt.std.03": "float64", | |
| # "chroma_cqt.std.04": "float64", | |
| # "chroma_cqt.std.05": "float64", | |
| # "chroma_cqt.std.06": "float64", | |
| # "chroma_cqt.std.07": "float64", | |
| # "chroma_cqt.std.08": "float64", | |
| # "chroma_cqt.std.09": "float64", | |
| # "chroma_cqt.std.10": "float64", | |
| # "chroma_cqt.std.11": "float64", | |
| # "chroma_cqt.std.12": "float64", | |
| # "chroma_stft.kurtosis.01": "float64", | |
| # "chroma_stft.kurtosis.02": "float64", | |
| # "chroma_stft.kurtosis.03": "float64", | |
| # "chroma_stft.kurtosis.04": "float64", | |
| # "chroma_stft.kurtosis.05": "float64", | |
| # "chroma_stft.kurtosis.06": "float64", | |
| # "chroma_stft.kurtosis.07": "float64", | |
| # "chroma_stft.kurtosis.08": "float64", | |
| # "chroma_stft.kurtosis.09": "float64", | |
| # "chroma_stft.kurtosis.10": "float64", | |
| # "chroma_stft.kurtosis.11": "float64", | |
| # "chroma_stft.kurtosis.12": "float64", | |
| # "chroma_stft.max.01": "float64", | |
| # "chroma_stft.max.02": "float64", | |
| # "chroma_stft.max.03": "float64", | |
| # "chroma_stft.max.04": "float64", | |
| # "chroma_stft.max.05": "float64", | |
| # "chroma_stft.max.06": "float64", | |
| # "chroma_stft.max.07": "float64", | |
| # "chroma_stft.max.08": "float64", | |
| # "chroma_stft.max.09": "float64", | |
| # "chroma_stft.max.10": "float64", | |
| # "chroma_stft.max.11": "float64", | |
| # "chroma_stft.max.12": "float64", | |
| # "chroma_stft.mean.01": "float64", | |
| # "chroma_stft.mean.02": "float64", | |
| # "chroma_stft.mean.03": "float64", | |
| # "chroma_stft.mean.04": "float64", | |
| # "chroma_stft.mean.05": "float64", | |
| # "chroma_stft.mean.06": "float64", | |
| # "chroma_stft.mean.07": "float64", | |
| # "chroma_stft.mean.08": "float64", | |
| # "chroma_stft.mean.09": "float64", | |
| # "chroma_stft.mean.10": "float64", | |
| # "chroma_stft.mean.11": "float64", | |
| # "chroma_stft.mean.12": "float64", | |
| # "chroma_stft.median.01": "float64", | |
| # "chroma_stft.median.02": "float64", | |
| # "chroma_stft.median.03": "float64", | |
| # "chroma_stft.median.04": "float64", | |
| # "chroma_stft.median.05": "float64", | |
| # "chroma_stft.median.06": "float64", | |
| # "chroma_stft.median.07": "float64", | |
| # "chroma_stft.median.08": "float64", | |
| # "chroma_stft.median.09": "float64", | |
| # "chroma_stft.median.10": "float64", | |
| # "chroma_stft.median.11": "float64", | |
| # "chroma_stft.median.12": "float64", | |
| # "chroma_stft.min.01": "float64", | |
| # "chroma_stft.min.02": "float64", | |
| # "chroma_stft.min.03": "float64", | |
| # "chroma_stft.min.04": "float64", | |
| # "chroma_stft.min.05": "float64", | |
| # "chroma_stft.min.06": "float64", | |
| # "chroma_stft.min.07": "float64", | |
| # "chroma_stft.min.08": "float64", | |
| # "chroma_stft.min.09": "float64", | |
| # "chroma_stft.min.10": "float64", | |
| # "chroma_stft.min.11": "float64", | |
| # "chroma_stft.min.12": "float64", | |
| # "chroma_stft.skew.01": "float64", | |
| # "chroma_stft.skew.02": "float64", | |
| # "chroma_stft.skew.03": "float64", | |
| # "chroma_stft.skew.04": "float64", | |
| # "chroma_stft.skew.05": "float64", | |
| # "chroma_stft.skew.06": "float64", | |
| # "chroma_stft.skew.07": "float64", | |
| # "chroma_stft.skew.08": "float64", | |
| # "chroma_stft.skew.09": "float64", | |
| # "chroma_stft.skew.10": "float64", | |
| # "chroma_stft.skew.11": "float64", | |
| # "chroma_stft.skew.12": "float64", | |
| # "chroma_stft.std.01": "float64", | |
| # "chroma_stft.std.02": "float64", | |
| # "chroma_stft.std.03": "float64", | |
| # "chroma_stft.std.04": "float64", | |
| # "chroma_stft.std.05": "float64", | |
| # "chroma_stft.std.06": "float64", | |
| # "chroma_stft.std.07": "float64", | |
| # "chroma_stft.std.08": "float64", | |
| # "chroma_stft.std.09": "float64", | |
| # "chroma_stft.std.10": "float64", | |
| # "chroma_stft.std.11": "float64", | |
| # "chroma_stft.std.12": "float64", | |
| # "mfcc.kurtosis.01": "float64", | |
| # "mfcc.kurtosis.02": "float64", | |
| # "mfcc.kurtosis.03": "float64", | |
| # "mfcc.kurtosis.04": "float64", | |
| # "mfcc.kurtosis.05": "float64", | |
| # "mfcc.kurtosis.06": "float64", | |
| # "mfcc.kurtosis.07": "float64", | |
| # "mfcc.kurtosis.08": "float64", | |
| # "mfcc.kurtosis.09": "float64", | |
| # "mfcc.kurtosis.10": "float64", | |
| # "mfcc.kurtosis.11": "float64", | |
| # "mfcc.kurtosis.12": "float64", | |
| # "mfcc.kurtosis.13": "float64", | |
| # "mfcc.kurtosis.14": "float64", | |
| # "mfcc.kurtosis.15": "float64", | |
| # "mfcc.kurtosis.16": "float64", | |
| # "mfcc.kurtosis.17": "float64", | |
| # "mfcc.kurtosis.18": "float64", | |
| # "mfcc.kurtosis.19": "float64", | |
| # "mfcc.kurtosis.20": "float64", | |
| # "mfcc.max.01": "float64", | |
| # "mfcc.max.02": "float64", | |
| # "mfcc.max.03": "float64", | |
| # "mfcc.max.04": "float64", | |
| # "mfcc.max.05": "float64", | |
| # "mfcc.max.06": "float64", | |
| # "mfcc.max.07": "float64", | |
| # "mfcc.max.08": "float64", | |
| # "mfcc.max.09": "float64", | |
| # "mfcc.max.10": "float64", | |
| # "mfcc.max.11": "float64", | |
| # "mfcc.max.12": "float64", | |
| # "mfcc.max.13": "float64", | |
| # "mfcc.max.14": "float64", | |
| # "mfcc.max.15": "float64", | |
| # "mfcc.max.16": "float64", | |
| # "mfcc.max.17": "float64", | |
| # "mfcc.max.18": "float64", | |
| # "mfcc.max.19": "float64", | |
| # "mfcc.max.20": "float64", | |
| # "mfcc.mean.01": "float64", | |
| # "mfcc.mean.02": "float64", | |
| # "mfcc.mean.03": "float64", | |
| # "mfcc.mean.04": "float64", | |
| # "mfcc.mean.05": "float64", | |
| # "mfcc.mean.06": "float64", | |
| # "mfcc.mean.07": "float64", | |
| # "mfcc.mean.08": "float64", | |
| # "mfcc.mean.09": "float64", | |
| # "mfcc.mean.10": "float64", | |
| # "mfcc.mean.11": "float64", | |
| # "mfcc.mean.12": "float64", | |
| # "mfcc.mean.13": "float64", | |
| # "mfcc.mean.14": "float64", | |
| # "mfcc.mean.15": "float64", | |
| # "mfcc.mean.16": "float64", | |
| # "mfcc.mean.17": "float64", | |
| # "mfcc.mean.18": "float64", | |
| # "mfcc.mean.19": "float64", | |
| # "mfcc.mean.20": "float64", | |
| # "mfcc.median.01": "float64", | |
| # "mfcc.median.02": "float64", | |
| # "mfcc.median.03": "float64", | |
| # "mfcc.median.04": "float64", | |
| # "mfcc.median.05": "float64", | |
| # "mfcc.median.06": "float64", | |
| # "mfcc.median.07": "float64", | |
| # "mfcc.median.08": "float64", | |
| # "mfcc.median.09": "float64", | |
| # "mfcc.median.10": "float64", | |
| # "mfcc.median.11": "float64", | |
| # "mfcc.median.12": "float64", | |
| # "mfcc.median.13": "float64", | |
| # "mfcc.median.14": "float64", | |
| # "mfcc.median.15": "float64", | |
| # "mfcc.median.16": "float64", | |
| # "mfcc.median.17": "float64", | |
| # "mfcc.median.18": "float64", | |
| # "mfcc.median.19": "float64", | |
| # "mfcc.median.20": "float64", | |
| # "mfcc.min.01": "float64", | |
| # "mfcc.min.02": "float64", | |
| # "mfcc.min.03": "float64", | |
| # "mfcc.min.04": "float64", | |
| # "mfcc.min.05": "float64", | |
| # "mfcc.min.06": "float64", | |
| # "mfcc.min.07": "float64", | |
| # "mfcc.min.08": "float64", | |
| # "mfcc.min.09": "float64", | |
| # "mfcc.min.10": "float64", | |
| # "mfcc.min.11": "float64", | |
| # "mfcc.min.12": "float64", | |
| # "mfcc.min.13": "float64", | |
| # "mfcc.min.14": "float64", | |
| # "mfcc.min.15": "float64", | |
| # "mfcc.min.16": "float64", | |
| # "mfcc.min.17": "float64", | |
| # "mfcc.min.18": "float64", | |
| # "mfcc.min.19": "float64", | |
| # "mfcc.min.20": "float64", | |
| # "mfcc.skew.01": "float64", | |
| # "mfcc.skew.02": "float64", | |
| # "mfcc.skew.03": "float64", | |
| # "mfcc.skew.04": "float64", | |
| # "mfcc.skew.05": "float64", | |
| # "mfcc.skew.06": "float64", | |
| # "mfcc.skew.07": "float64", | |
| # "mfcc.skew.08": "float64", | |
| # "mfcc.skew.09": "float64", | |
| # "mfcc.skew.10": "float64", | |
| # "mfcc.skew.11": "float64", | |
| # "mfcc.skew.12": "float64", | |
| # "mfcc.skew.13": "float64", | |
| # "mfcc.skew.14": "float64", | |
| # "mfcc.skew.15": "float64", | |
| # "mfcc.skew.16": "float64", | |
| # "mfcc.skew.17": "float64", | |
| # "mfcc.skew.18": "float64", | |
| # "mfcc.skew.19": "float64", | |
| # "mfcc.skew.20": "float64", | |
| # "mfcc.std.01": "float64", | |
| # "mfcc.std.02": "float64", | |
| # "mfcc.std.03": "float64", | |
| # "mfcc.std.04": "float64", | |
| # "mfcc.std.05": "float64", | |
| # "mfcc.std.06": "float64", | |
| # "mfcc.std.07": "float64", | |
| # "mfcc.std.08": "float64", | |
| # "mfcc.std.09": "float64", | |
| # "mfcc.std.10": "float64", | |
| # "mfcc.std.11": "float64", | |
| # "mfcc.std.12": "float64", | |
| # "mfcc.std.13": "float64", | |
| # "mfcc.std.14": "float64", | |
| # "mfcc.std.15": "float64", | |
| # "mfcc.std.16": "float64", | |
| # "mfcc.std.17": "float64", | |
| # "mfcc.std.18": "float64", | |
| # "mfcc.std.19": "float64", | |
| # "mfcc.std.20": "float64", | |
| # "rmse.kurtosis.01": "float64", | |
| # "rmse.max.01": "float64", | |
| # "rmse.mean.01": "float64", | |
| # "rmse.median.01": "float64", | |
| # "rmse.min.01": "float64", | |
| # "rmse.skew.01": "float64", | |
| # "rmse.std.01": "float64", | |
| # "spectral_bandwidth.kurtosis.01": "float64", | |
| # "spectral_bandwidth.max.01": "float64", | |
| # "spectral_bandwidth.mean.01": "float64", | |
| # "spectral_bandwidth.median.01": "float64", | |
| # "spectral_bandwidth.min.01": "float64", | |
| # "spectral_bandwidth.skew.01": "float64", | |
| # "spectral_bandwidth.std.01": "float64", | |
| # "spectral_centroid.kurtosis.01": "float64", | |
| # "spectral_centroid.max.01": "float64", | |
| # "spectral_centroid.mean.01": "float64", | |
| # "spectral_centroid.median.01": "float64", | |
| # "spectral_centroid.min.01": "float64", | |
| # "spectral_centroid.skew.01": "float64", | |
| # "spectral_centroid.std.01": "float64", | |
| # "spectral_contrast.kurtosis.01": "float64", | |
| # "spectral_contrast.kurtosis.02": "float64", | |
| # "spectral_contrast.kurtosis.03": "float64", | |
| # "spectral_contrast.kurtosis.04": "float64", | |
| # "spectral_contrast.kurtosis.05": "float64", | |
| # "spectral_contrast.kurtosis.06": "float64", | |
| # "spectral_contrast.kurtosis.07": "float64", | |
| # "spectral_contrast.max.01": "float64", | |
| # "spectral_contrast.max.02": "float64", | |
| # "spectral_contrast.max.03": "float64", | |
| # "spectral_contrast.max.04": "float64", | |
| # "spectral_contrast.max.05": "float64", | |
| # "spectral_contrast.max.06": "float64", | |
| # "spectral_contrast.max.07": "float64", | |
| # "spectral_contrast.mean.01": "float64", | |
| # "spectral_contrast.mean.02": "float64", | |
| # "spectral_contrast.mean.03": "float64", | |
| # "spectral_contrast.mean.04": "float64", | |
| # "spectral_contrast.mean.05": "float64", | |
| # "spectral_contrast.mean.06": "float64", | |
| # "spectral_contrast.mean.07": "float64", | |
| # "spectral_contrast.median.01": "float64", | |
| # "spectral_contrast.median.02": "float64", | |
| # "spectral_contrast.median.03": "float64", | |
| # "spectral_contrast.median.04": "float64", | |
| # "spectral_contrast.median.05": "float64", | |
| # "spectral_contrast.median.06": "float64", | |
| # "spectral_contrast.median.07": "float64", | |
| # "spectral_contrast.min.01": "float64", | |
| # "spectral_contrast.min.02": "float64", | |
| # "spectral_contrast.min.03": "float64", | |
| # "spectral_contrast.min.04": "float64", | |
| # "spectral_contrast.min.05": "float64", | |
| # "spectral_contrast.min.06": "float64", | |
| # "spectral_contrast.min.07": "float64", | |
| # "spectral_contrast.skew.01": "float64", | |
| # "spectral_contrast.skew.02": "float64", | |
| # "spectral_contrast.skew.03": "float64", | |
| # "spectral_contrast.skew.04": "float64", | |
| # "spectral_contrast.skew.05": "float64", | |
| # "spectral_contrast.skew.06": "float64", | |
| # "spectral_contrast.skew.07": "float64", | |
| # "spectral_contrast.std.01": "float64", | |
| # "spectral_contrast.std.02": "float64", | |
| # "spectral_contrast.std.03": "float64", | |
| # "spectral_contrast.std.04": "float64", | |
| # "spectral_contrast.std.05": "float64", | |
| # "spectral_contrast.std.06": "float64", | |
| # "spectral_contrast.std.07": "float64", | |
| # "spectral_rolloff.kurtosis.01": "float64", | |
| # "spectral_rolloff.max.01": "float64", | |
| # "spectral_rolloff.mean.01": "float64", | |
| # "spectral_rolloff.median.01": "float64", | |
| # "spectral_rolloff.min.01": "float64", | |
| # "spectral_rolloff.skew.01": "float64", | |
| # "spectral_rolloff.std.01": "float64", | |
| # "tonnetz.kurtosis.01": "float64", | |
| # "tonnetz.kurtosis.02": "float64", | |
| # "tonnetz.kurtosis.03": "float64", | |
| # "tonnetz.kurtosis.04": "float64", | |
| # "tonnetz.kurtosis.05": "float64", | |
| # "tonnetz.kurtosis.06": "float64", | |
| # "tonnetz.max.01": "float64", | |
| # "tonnetz.max.02": "float64", | |
| # "tonnetz.max.03": "float64", | |
| # "tonnetz.max.04": "float64", | |
| # "tonnetz.max.05": "float64", | |
| # "tonnetz.max.06": "float64", | |
| # "tonnetz.mean.01": "float64", | |
| # "tonnetz.mean.02": "float64", | |
| # "tonnetz.mean.03": "float64", | |
| # "tonnetz.mean.04": "float64", | |
| # "tonnetz.mean.05": "float64", | |
| # "tonnetz.mean.06": "float64", | |
| # "tonnetz.median.01": "float64", | |
| # "tonnetz.median.02": "float64", | |
| # "tonnetz.median.03": "float64", | |
| # "tonnetz.median.04": "float64", | |
| # "tonnetz.median.05": "float64", | |
| # "tonnetz.median.06": "float64", | |
| # "tonnetz.min.01": "float64", | |
| # "tonnetz.min.02": "float64", | |
| # "tonnetz.min.03": "float64", | |
| # "tonnetz.min.04": "float64", | |
| # "tonnetz.min.05": "float64", | |
| # "tonnetz.min.06": "float64", | |
| # "tonnetz.skew.01": "float64", | |
| # "tonnetz.skew.02": "float64", | |
| # "tonnetz.skew.03": "float64", | |
| # "tonnetz.skew.04": "float64", | |
| # "tonnetz.skew.05": "float64", | |
| # "tonnetz.skew.06": "float64", | |
| # "tonnetz.std.01": "float64", | |
| # "tonnetz.std.02": "float64", | |
| # "tonnetz.std.03": "float64", | |
| # "tonnetz.std.04": "float64", | |
| # "tonnetz.std.05": "float64", | |
| # "tonnetz.std.06": "float64", | |
| # "zcr.kurtosis.01": "float64", | |
| # "zcr.max.01": "float64", | |
| # "zcr.mean.01": "float64", | |
| # "zcr.median.01": "float64", | |
| # "zcr.min.01": "float64", | |
| # "zcr.skew.01": "float64", | |
| # "zcr.std.01": "float64", | |
| # Echo Nest | |
| "echonest.audio_features.acousticness": "float64", | |
| "echonest.audio_features.danceability": "float64", | |
| "echonest.audio_features.energy": "float64", | |
| "echonest.audio_features.instrumentalness": "float64", | |
| "echonest.audio_features.liveness": "float64", | |
| "echonest.audio_features.speechiness": "float64", | |
| "echonest.audio_features.tempo": "float64", | |
| "echonest.audio_features.valence": "float64", | |
| "echonest.metadata.album_date": "object", | |
| "echonest.metadata.album_name": "object", | |
| "echonest.metadata.artist_latitude": "float64", | |
| "echonest.metadata.artist_location": "object", | |
| "echonest.metadata.artist_longitude": "float64", | |
| "echonest.metadata.artist_name": "object", | |
| "echonest.metadata.release": "object", | |
| "echonest.ranks.artist_discovery_rank": "float64", | |
| "echonest.ranks.artist_familiarity_rank": "float64", | |
| "echonest.ranks.artist_hotttnesss_rank": "float64", | |
| "echonest.ranks.song_currency_rank": "float64", | |
| "echonest.ranks.song_hotttnesss_rank": "float64", | |
| "echonest.social_features.artist_discovery": "float64", | |
| "echonest.social_features.artist_familiarity": "float64", | |
| "echonest.social_features.artist_hotttnesss": "float64", | |
| "echonest.social_features.song_currency": "float64", | |
| "echonest.social_features.song_hotttnesss": "float64", | |
| "echonest.temporal_features.000": "float64", | |
| "echonest.temporal_features.001": "float64", | |
| "echonest.temporal_features.002": "float64", | |
| "echonest.temporal_features.003": "float64", | |
| "echonest.temporal_features.004": "float64", | |
| "echonest.temporal_features.005": "float64", | |
| "echonest.temporal_features.006": "float64", | |
| "echonest.temporal_features.007": "float64", | |
| "echonest.temporal_features.008": "float64", | |
| "echonest.temporal_features.009": "float64", | |
| "echonest.temporal_features.010": "float64", | |
| "echonest.temporal_features.011": "float64", | |
| "echonest.temporal_features.012": "float64", | |
| "echonest.temporal_features.013": "float64", | |
| "echonest.temporal_features.014": "float64", | |
| "echonest.temporal_features.015": "float64", | |
| "echonest.temporal_features.016": "float64", | |
| "echonest.temporal_features.017": "float64", | |
| "echonest.temporal_features.018": "float64", | |
| "echonest.temporal_features.019": "float64", | |
| "echonest.temporal_features.020": "float64", | |
| "echonest.temporal_features.021": "float64", | |
| "echonest.temporal_features.022": "float64", | |
| "echonest.temporal_features.023": "float64", | |
| "echonest.temporal_features.024": "float64", | |
| "echonest.temporal_features.025": "float64", | |
| "echonest.temporal_features.026": "float64", | |
| "echonest.temporal_features.027": "float64", | |
| "echonest.temporal_features.028": "float64", | |
| "echonest.temporal_features.029": "float64", | |
| "echonest.temporal_features.030": "float64", | |
| "echonest.temporal_features.031": "float64", | |
| "echonest.temporal_features.032": "float64", | |
| "echonest.temporal_features.033": "float64", | |
| "echonest.temporal_features.034": "float64", | |
| "echonest.temporal_features.035": "float64", | |
| "echonest.temporal_features.036": "float64", | |
| "echonest.temporal_features.037": "float64", | |
| "echonest.temporal_features.038": "float64", | |
| "echonest.temporal_features.039": "float64", | |
| "echonest.temporal_features.040": "float64", | |
| "echonest.temporal_features.041": "float64", | |
| "echonest.temporal_features.042": "float64", | |
| "echonest.temporal_features.043": "float64", | |
| "echonest.temporal_features.044": "float64", | |
| "echonest.temporal_features.045": "float64", | |
| "echonest.temporal_features.046": "float64", | |
| "echonest.temporal_features.047": "float64", | |
| "echonest.temporal_features.048": "float64", | |
| "echonest.temporal_features.049": "float64", | |
| "echonest.temporal_features.050": "float64", | |
| "echonest.temporal_features.051": "float64", | |
| "echonest.temporal_features.052": "float64", | |
| "echonest.temporal_features.053": "float64", | |
| "echonest.temporal_features.054": "float64", | |
| "echonest.temporal_features.055": "float64", | |
| "echonest.temporal_features.056": "float64", | |
| "echonest.temporal_features.057": "float64", | |
| "echonest.temporal_features.058": "float64", | |
| "echonest.temporal_features.059": "float64", | |
| "echonest.temporal_features.060": "float64", | |
| "echonest.temporal_features.061": "float64", | |
| "echonest.temporal_features.062": "float64", | |
| "echonest.temporal_features.063": "float64", | |
| "echonest.temporal_features.064": "float64", | |
| "echonest.temporal_features.065": "float64", | |
| "echonest.temporal_features.066": "float64", | |
| "echonest.temporal_features.067": "float64", | |
| "echonest.temporal_features.068": "float64", | |
| "echonest.temporal_features.069": "float64", | |
| "echonest.temporal_features.070": "float64", | |
| "echonest.temporal_features.071": "float64", | |
| "echonest.temporal_features.072": "float64", | |
| "echonest.temporal_features.073": "float64", | |
| "echonest.temporal_features.074": "float64", | |
| "echonest.temporal_features.075": "float64", | |
| "echonest.temporal_features.076": "float64", | |
| "echonest.temporal_features.077": "float64", | |
| "echonest.temporal_features.078": "float64", | |
| "echonest.temporal_features.079": "float64", | |
| "echonest.temporal_features.080": "float64", | |
| "echonest.temporal_features.081": "float64", | |
| "echonest.temporal_features.082": "float64", | |
| "echonest.temporal_features.083": "float64", | |
| "echonest.temporal_features.084": "float64", | |
| "echonest.temporal_features.085": "float64", | |
| "echonest.temporal_features.086": "float64", | |
| "echonest.temporal_features.087": "float64", | |
| "echonest.temporal_features.088": "float64", | |
| "echonest.temporal_features.089": "float64", | |
| "echonest.temporal_features.090": "float64", | |
| "echonest.temporal_features.091": "float64", | |
| "echonest.temporal_features.092": "float64", | |
| "echonest.temporal_features.093": "float64", | |
| "echonest.temporal_features.094": "float64", | |
| "echonest.temporal_features.095": "float64", | |
| "echonest.temporal_features.096": "float64", | |
| "echonest.temporal_features.097": "float64", | |
| "echonest.temporal_features.098": "float64", | |
| "echonest.temporal_features.099": "float64", | |
| "echonest.temporal_features.100": "float64", | |
| "echonest.temporal_features.101": "float64", | |
| "echonest.temporal_features.102": "float64", | |
| "echonest.temporal_features.103": "float64", | |
| "echonest.temporal_features.104": "float64", | |
| "echonest.temporal_features.105": "float64", | |
| "echonest.temporal_features.106": "float64", | |
| "echonest.temporal_features.107": "float64", | |
| "echonest.temporal_features.108": "float64", | |
| "echonest.temporal_features.109": "float64", | |
| "echonest.temporal_features.110": "float64", | |
| "echonest.temporal_features.111": "float64", | |
| "echonest.temporal_features.112": "float64", | |
| "echonest.temporal_features.113": "float64", | |
| "echonest.temporal_features.114": "float64", | |
| "echonest.temporal_features.115": "float64", | |
| "echonest.temporal_features.116": "float64", | |
| "echonest.temporal_features.117": "float64", | |
| "echonest.temporal_features.118": "float64", | |
| "echonest.temporal_features.119": "float64", | |
| "echonest.temporal_features.120": "float64", | |
| "echonest.temporal_features.121": "float64", | |
| "echonest.temporal_features.122": "float64", | |
| "echonest.temporal_features.123": "float64", | |
| "echonest.temporal_features.124": "float64", | |
| "echonest.temporal_features.125": "float64", | |
| "echonest.temporal_features.126": "float64", | |
| "echonest.temporal_features.127": "float64", | |
| "echonest.temporal_features.128": "float64", | |
| "echonest.temporal_features.129": "float64", | |
| "echonest.temporal_features.130": "float64", | |
| "echonest.temporal_features.131": "float64", | |
| "echonest.temporal_features.132": "float64", | |
| "echonest.temporal_features.133": "float64", | |
| "echonest.temporal_features.134": "float64", | |
| "echonest.temporal_features.135": "float64", | |
| "echonest.temporal_features.136": "float64", | |
| "echonest.temporal_features.137": "float64", | |
| "echonest.temporal_features.138": "float64", | |
| "echonest.temporal_features.139": "float64", | |
| "echonest.temporal_features.140": "float64", | |
| "echonest.temporal_features.141": "float64", | |
| "echonest.temporal_features.142": "float64", | |
| "echonest.temporal_features.143": "float64", | |
| "echonest.temporal_features.144": "float64", | |
| "echonest.temporal_features.145": "float64", | |
| "echonest.temporal_features.146": "float64", | |
| "echonest.temporal_features.147": "float64", | |
| "echonest.temporal_features.148": "float64", | |
| "echonest.temporal_features.149": "float64", | |
| "echonest.temporal_features.150": "float64", | |
| "echonest.temporal_features.151": "float64", | |
| "echonest.temporal_features.152": "float64", | |
| "echonest.temporal_features.153": "float64", | |
| "echonest.temporal_features.154": "float64", | |
| "echonest.temporal_features.155": "float64", | |
| "echonest.temporal_features.156": "float64", | |
| "echonest.temporal_features.157": "float64", | |
| "echonest.temporal_features.158": "float64", | |
| "echonest.temporal_features.159": "float64", | |
| "echonest.temporal_features.160": "float64", | |
| "echonest.temporal_features.161": "float64", | |
| "echonest.temporal_features.162": "float64", | |
| "echonest.temporal_features.163": "float64", | |
| "echonest.temporal_features.164": "float64", | |
| "echonest.temporal_features.165": "float64", | |
| "echonest.temporal_features.166": "float64", | |
| "echonest.temporal_features.167": "float64", | |
| "echonest.temporal_features.168": "float64", | |
| "echonest.temporal_features.169": "float64", | |
| "echonest.temporal_features.170": "float64", | |
| "echonest.temporal_features.171": "float64", | |
| "echonest.temporal_features.172": "float64", | |
| "echonest.temporal_features.173": "float64", | |
| "echonest.temporal_features.174": "float64", | |
| "echonest.temporal_features.175": "float64", | |
| "echonest.temporal_features.176": "float64", | |
| "echonest.temporal_features.177": "float64", | |
| "echonest.temporal_features.178": "float64", | |
| "echonest.temporal_features.179": "float64", | |
| "echonest.temporal_features.180": "float64", | |
| "echonest.temporal_features.181": "float64", | |
| "echonest.temporal_features.182": "float64", | |
| "echonest.temporal_features.183": "float64", | |
| "echonest.temporal_features.184": "float64", | |
| "echonest.temporal_features.185": "float64", | |
| "echonest.temporal_features.186": "float64", | |
| "echonest.temporal_features.187": "float64", | |
| "echonest.temporal_features.188": "float64", | |
| "echonest.temporal_features.189": "float64", | |
| "echonest.temporal_features.190": "float64", | |
| "echonest.temporal_features.191": "float64", | |
| "echonest.temporal_features.192": "float64", | |
| "echonest.temporal_features.193": "float64", | |
| "echonest.temporal_features.194": "float64", | |
| "echonest.temporal_features.195": "float64", | |
| "echonest.temporal_features.196": "float64", | |
| "echonest.temporal_features.197": "float64", | |
| "echonest.temporal_features.198": "float64", | |
| "echonest.temporal_features.199": "float64", | |
| "echonest.temporal_features.200": "float64", | |
| "echonest.temporal_features.201": "float64", | |
| "echonest.temporal_features.202": "float64", | |
| "echonest.temporal_features.203": "float64", | |
| "echonest.temporal_features.204": "float64", | |
| "echonest.temporal_features.205": "float64", | |
| "echonest.temporal_features.206": "float64", | |
| "echonest.temporal_features.207": "float64", | |
| "echonest.temporal_features.208": "float64", | |
| "echonest.temporal_features.209": "float64", | |
| "echonest.temporal_features.210": "float64", | |
| "echonest.temporal_features.211": "float64", | |
| "echonest.temporal_features.212": "float64", | |
| "echonest.temporal_features.213": "float64", | |
| "echonest.temporal_features.214": "float64", | |
| "echonest.temporal_features.215": "float64", | |
| "echonest.temporal_features.216": "float64", | |
| "echonest.temporal_features.217": "float64", | |
| "echonest.temporal_features.218": "float64", | |
| "echonest.temporal_features.219": "float64", | |
| "echonest.temporal_features.220": "float64", | |
| "echonest.temporal_features.221": "float64", | |
| "echonest.temporal_features.222": "float64", | |
| "echonest.temporal_features.223": "float64", | |
| } | |
| class FMADataset(datasets.GeneratorBasedBuilder): | |
| """FMA.""" | |
| VERSION = datasets.Version("1.0.0") | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig( | |
| name=f"small", version=VERSION, description="8,000 tracks of 30s, 8 balanced genres (GTZAN-like) (7.2 GiB)" | |
| ), | |
| datasets.BuilderConfig( | |
| name=f"medium", version=VERSION, description="25,000 tracks of 30s, 16 unbalanced genres (22 GiB)" | |
| ), | |
| datasets.BuilderConfig( | |
| name=f"large", version=VERSION, description="106,574 tracks of 30s, 161 unbalanced genres (93 GiB)" | |
| ), | |
| datasets.BuilderConfig(name=f"all", version=VERSION, description="All splits together"), | |
| ] | |
| def _info(self): | |
| def parseValueType(dtype): | |
| try: | |
| return datasets.Value(dtype) | |
| except: | |
| return datasets.Value("string") | |
| return datasets.DatasetInfo( | |
| # This is the description that will appear on the datasets page. | |
| description=_DESCRIPTION, | |
| features=datasets.Features( | |
| { | |
| "id": datasets.Value("int32"), | |
| "audio": datasets.features.Audio(), | |
| **{k: parseValueType(v) for k, v in METADATA_FIELDS.items()}, | |
| } | |
| ), | |
| supervised_keys=None, | |
| homepage=_HOMEPAGE, | |
| license=_LICENSE, | |
| citation=_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager): | |
| """Returns SplitGenerators.""" | |
| # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name | |
| # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs | |
| # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files. | |
| # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive | |
| metadata = dl_manager.download(dataset_links["metadata"]) | |
| metadata = dl_manager.iter_archive(metadata) | |
| for f in metadata: | |
| if f[0] == "fma_metadata/tracks.csv": | |
| tracks = utils_load(*f) | |
| elif f[0] == "fma_metadata/genres.csv": | |
| genres = None # utils_load(*f) | |
| elif f[0] == "fma_metadata/features.csv": | |
| features = None # utils_load(*f) | |
| elif f[0] == "fma_metadata/echonest.csv": | |
| echonest = utils_load(*f) | |
| metadata = read_metadata(tracks, genres, features, echonest) | |
| audio = dl_manager.download(dataset_links[self.config.name if self.config.name != "all" else "large"]) | |
| audio = dl_manager.iter_archive(audio) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| # These kwargs will be passed to _generate_examples | |
| gen_kwargs={ | |
| "audio": audio, | |
| "metadata": metadata, | |
| "split": "training", | |
| }, | |
| ), | |
| datasets.SplitGenerator( | |
| name=datasets.Split.VALIDATION, | |
| # These kwargs will be passed to _generate_examples | |
| gen_kwargs={ | |
| "audio": audio, | |
| "metadata": metadata, | |
| "split": "validation", | |
| }, | |
| ), | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TEST, | |
| # These kwargs will be passed to _generate_examples | |
| gen_kwargs={ | |
| "audio": audio, | |
| "metadata": metadata, | |
| "split": "test", | |
| }, | |
| ), | |
| ] | |
| def _generate_examples(self, audio, metadata, split): | |
| """Yields examples as (key, example) tuples.""" | |
| # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset. | |
| # The `key` is here for legacy reason (tfds) and is not important in itself. | |
| import os | |
| for audio_path, f in audio: | |
| try: | |
| track_id = int(os.path.splitext(os.path.basename(audio_path))[0]) | |
| except: | |
| # README or checksums or some other non-audio file | |
| continue | |
| track_metadata = metadata.tracks.loc[track_id].to_dict() | |
| if track_metadata["set.split"] != split: | |
| continue | |
| if track_metadata["set.subset"] != self.config.name and not self.config.name == "all": | |
| continue | |
| try: | |
| echonest_features = metadata.echonest.loc[track_id].to_dict() | |
| except: | |
| echonest_features = {k: None for k in metadata.echonest.columns.values.tolist()} | |
| yield track_id, { | |
| "id": track_id, | |
| "audio": {"path": audio_path, "bytes": f.read()}, | |
| **track_metadata, | |
| **echonest_features, | |
| } | |
| ## DEPRECATED | |
| # def download(dset_version: str, zip_prefix: str): | |
| # from tqdm import tqdm | |
| # import os | |
| # import requests | |
| # zip_filename = os.path.join(zip_prefix, f"fma_{dset_version}.zip") | |
| # with tqdm(desc=f"(GB - not exact) Downloading {zip_filename}") as pbar: | |
| # with requests.get(dataset_links[dset_version], stream=True) as r: | |
| # r.raise_for_status() | |
| # with open(zip_filename, "wb") as f: | |
| # for i, chunk in enumerate(r.iter_content(chunk_size=8192)): | |
| # if i % 125000 == 0: | |
| # pbar.update(1) | |
| # f.write(chunk) | |
| # print(f"Downloaded {dset_version} ZIP") | |
| # def extract_metadata(zip_prefix: str, extraction_prefix: str): | |
| # import os | |
| # from zipfile import ZipFile | |
| # from tqdm import tqdm | |
| # os.makedirs(os.path.join(zip_prefix, "metadata"), exist_ok=True) | |
| # zip_filename = os.path.join(zip_prefix, f"fma_metadata.zip") | |
| # with ZipFile(zip_filename, "r") as handle: | |
| # members = handle.namelist() | |
| # for member in tqdm( | |
| # members, | |
| # ncols=0, | |
| # mininterval=10, | |
| # maxinterval=30, | |
| # desc="Extracting metadata", | |
| # ): | |
| # handle.extract(member, os.path.join(zip_prefix, "metadata")) | |
| # print("Metadata extraction complete") | |
| # def extract(dset_version: str, zip_prefix: str, extraction_prefix: str): | |
| # from zipfile import ZipFile | |
| # import os | |
| # import requests | |
| # from tqdm import tqdm | |
| # import random | |
| # import shutil | |
| # if dset_version == "metadata": | |
| # extract_metadata(zip_prefix, extraction_prefix) | |
| # return | |
| # metadata = read_metadata(zip_prefix) | |
| # zip_filename = os.path.join(zip_prefix, f"fma_{dset_version}.zip") | |
| # with ZipFile(zip_filename, "r") as handle: | |
| # random.seed(0) | |
| # members = handle.namelist() | |
| # random.shuffle(members) | |
| # for member in tqdm( | |
| # members, | |
| # ncols=0, | |
| # mininterval=10, | |
| # maxinterval=30, | |
| # desc="Uploading to Huggingface Datasets", | |
| # ): | |
| # # sink.write( | |
| # # { | |
| # # "__key__": member[4:].replace("/", "_").replace(".mp3", ""), | |
| # # "mp3": handle.read(member), | |
| # # } | |
| # # ) | |
| # # if sink.fname != current_local_shard: | |
| # # shutil.copyfile( | |
| # # current_local_shard, | |
| # # os.path.join( | |
| # # extraction_prefix, | |
| # # dset_version, | |
| # # os.path.basename(current_local_shard), | |
| # # ), | |
| # # ) | |
| # # os.remove(current_local_shard) | |
| # # current_local_shard = sink.fname | |
| # print("Upload complete") | |