Datasets:
Tasks:
Audio Classification
Modalities:
Audio
Languages:
English
Tags:
audio
music-classification
meter-classification
multi-class-classification
multi-label-classification
License:
Delete testing_dataset_on _hf.ipynb
Browse files- testing_dataset_on _hf.ipynb +0 -127
testing_dataset_on _hf.ipynb
DELETED
|
@@ -1,127 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "markdown",
|
| 5 |
-
"id": "ac18fe04-6056-4a82-9cf8-f530aca2559c",
|
| 6 |
-
"metadata": {},
|
| 7 |
-
"source": [
|
| 8 |
-
"How to Use Your pianistprogrammer/Meter2800 Dataset\n",
|
| 9 |
-
"Since your dataset contains both metadata in CSVs and raw audio files, the datasets library can intelligently load them. The key is how you organize your README.md on Hugging Face (or how the load_dataset function infers it).\n",
|
| 10 |
-
"\n",
|
| 11 |
-
"1. Install Necessary Libraries\n",
|
| 12 |
-
"First, make sure you have the datasets and pandas (for easier data handling if needed) libraries installed. Also, soundfile and librosa are often useful for audio processing, and ffmpeg is required by datasets to process audio files.\n",
|
| 13 |
-
"\n",
|
| 14 |
-
"pip install datasets pandas soundfile librosa\n",
|
| 15 |
-
"# Ensure ffmpeg is installed on your system (see previous script for instructions)\n",
|
| 16 |
-
"\n",
|
| 17 |
-
"2. Loading the Dataset\n",
|
| 18 |
-
"You can load your dataset using load_dataset. The data_files argument is crucial here to tell datasets which CSVs correspond to which splits. The audio files will be loaded alongside if they are correctly referenced in the CSVs and available in the same repository.\n"
|
| 19 |
-
]
|
| 20 |
-
},
|
| 21 |
-
{
|
| 22 |
-
"cell_type": "code",
|
| 23 |
-
"execution_count": null,
|
| 24 |
-
"id": "d2e55e10-0fe7-4645-a529-7ad0b52053d3",
|
| 25 |
-
"metadata": {},
|
| 26 |
-
"outputs": [],
|
| 27 |
-
"source": [
|
| 28 |
-
"from datasets import load_dataset, Audio\n",
|
| 29 |
-
"import os\n",
|
| 30 |
-
"import pandas as pd\n",
|
| 31 |
-
"\n",
|
| 32 |
-
"# Define the dataset name on Hugging Face Hub\n",
|
| 33 |
-
"dataset_name = \"pianistprogrammer/Meter2800\"\n",
|
| 34 |
-
"\n",
|
| 35 |
-
"# Define the paths to your CSV files within the Hugging Face repository\n",
|
| 36 |
-
"# Assuming your CSVs are at the root of your uploaded folder\n",
|
| 37 |
-
"data_files = {\n",
|
| 38 |
-
" 'train_4_classes': 'data_train_4_classes.csv',\n",
|
| 39 |
-
" 'val_4_classes': 'data_val_4_classes.csv',\n",
|
| 40 |
-
" 'test_4_classes': 'data_test_4_classes.csv',\n",
|
| 41 |
-
" # Include your 2-class CSVs if you want to load them too\n",
|
| 42 |
-
" 'train_2_classes': 'data_train_2_classes.csv',\n",
|
| 43 |
-
" 'val_2_classes': 'data_val_2_classes.csv',\n",
|
| 44 |
-
" 'test_2_classes': 'data_test_2_classes.csv',\n",
|
| 45 |
-
"}\n",
|
| 46 |
-
"\n",
|
| 47 |
-
"try:\n",
|
| 48 |
-
" # Load the dataset\n",
|
| 49 |
-
" # The 'filename' column will be automatically treated as a path to an audio file\n",
|
| 50 |
-
" # if the `Audio` feature type is specified.\n",
|
| 51 |
-
" # The `data_dir` argument helps `datasets` locate the actual audio files\n",
|
| 52 |
-
" # within the repository. Since your folders (GTZAN, MAG, OWN, FMA) are\n",
|
| 53 |
-
" # in the root of the uploaded dataset, this should work.\n",
|
| 54 |
-
" dataset = load_dataset(dataset_name, data_files=data_files, split='train_4_classes') # Example: load just one split first\n",
|
| 55 |
-
"\n",
|
| 56 |
-
" # To load all splits at once:\n",
|
| 57 |
-
" # dataset_dict = load_dataset(dataset_name, data_files=data_files)\n",
|
| 58 |
-
"\n",
|
| 59 |
-
" print(f\"Dataset loaded successfully from {dataset_name}!\")\n",
|
| 60 |
-
" print(dataset)\n",
|
| 61 |
-
" print(f\"First example from 'train_4_classes':\")\n",
|
| 62 |
-
" print(dataset[0])\n",
|
| 63 |
-
"\n",
|
| 64 |
-
" # Accessing an audio file - this will automatically load the audio data\n",
|
| 65 |
-
" # The 'Audio' feature type handles the loading and provides sampling rate, array data.\n",
|
| 66 |
-
" first_example = dataset[0]\n",
|
| 67 |
-
" print(f\"\\nAudio path: {first_example['filename']}\")\n",
|
| 68 |
-
" print(f\"Audio array (first 10 samples): {first_example['audio']['array'][:10]}\")\n",
|
| 69 |
-
" print(f\"Sampling rate: {first_example['audio']['sampling_rate']}\")\n",
|
| 70 |
-
"\n",
|
| 71 |
-
" # Example of iterating through a dataset split\n",
|
| 72 |
-
" # for i, example in enumerate(dataset):\n",
|
| 73 |
-
" # if i >= 3: # Just process first 3 examples\n",
|
| 74 |
-
" # break\n",
|
| 75 |
-
" # print(f\"\\nExample {i+1}:\")\n",
|
| 76 |
-
" # print(f\" Filename: {example['filename']}\")\n",
|
| 77 |
-
" # print(f\" Label: {example['label']}\")\n",
|
| 78 |
-
" # print(f\" Audio data shape: {example['audio']['array'].shape}\")\n",
|
| 79 |
-
"\n",
|
| 80 |
-
"except Exception as e:\n",
|
| 81 |
-
" print(f\"Error loading dataset: {e}\")\n",
|
| 82 |
-
" print(\"Please ensure your dataset is public or you're authenticated if it's private.\")\n",
|
| 83 |
-
" print(\"Also, verify the structure of your CSV 'filename' column matches paths within the dataset repository (e.g., '/GTZAN/rock.00056.wav').\")\n",
|
| 84 |
-
"\n",
|
| 85 |
-
"# --- Combining splits (Optional) ---\n",
|
| 86 |
-
"# If you want to work with a combined dataset (e.g., all 4-class data),\n",
|
| 87 |
-
"# you can concatenate the splits after loading.\n",
|
| 88 |
-
"# This requires loading all splits first.\n",
|
| 89 |
-
"# try:\n",
|
| 90 |
-
"# dataset_dict = load_dataset(dataset_name, data_files={\n",
|
| 91 |
-
"# 'train': 'data_train_4_classes.csv',\n",
|
| 92 |
-
"# 'validation': 'data_val_4_classes.csv',\n",
|
| 93 |
-
"# 'test': 'data_test_4_classes.csv'\n",
|
| 94 |
-
"# })\n",
|
| 95 |
-
"# print(\"\\nLoaded dataset dictionary:\")\n",
|
| 96 |
-
"# print(dataset_dict)\n",
|
| 97 |
-
"\n",
|
| 98 |
-
"# # To combine them into a single dataset for easier iteration\n",
|
| 99 |
-
"# # combined_dataset = concatenate_datasets([dataset_dict['train'], dataset_dict['validation'], dataset_dict['test']])\n",
|
| 100 |
-
"# # print(f\"\\nCombined dataset size: {len(combined_dataset)}\")\n",
|
| 101 |
-
"# except Exception as e:\n",
|
| 102 |
-
"# print(f\"Error loading multiple splits or combining them: {e}\")"
|
| 103 |
-
]
|
| 104 |
-
}
|
| 105 |
-
],
|
| 106 |
-
"metadata": {
|
| 107 |
-
"kernelspec": {
|
| 108 |
-
"display_name": "Python 3 (ipykernel)",
|
| 109 |
-
"language": "python",
|
| 110 |
-
"name": "python3"
|
| 111 |
-
},
|
| 112 |
-
"language_info": {
|
| 113 |
-
"codemirror_mode": {
|
| 114 |
-
"name": "ipython",
|
| 115 |
-
"version": 3
|
| 116 |
-
},
|
| 117 |
-
"file_extension": ".py",
|
| 118 |
-
"mimetype": "text/x-python",
|
| 119 |
-
"name": "python",
|
| 120 |
-
"nbconvert_exporter": "python",
|
| 121 |
-
"pygments_lexer": "ipython3",
|
| 122 |
-
"version": "3.11.9"
|
| 123 |
-
}
|
| 124 |
-
},
|
| 125 |
-
"nbformat": 4,
|
| 126 |
-
"nbformat_minor": 5
|
| 127 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|