-
-
Save parulnith/7f8c174e6ac099e86f0495d3d9a4c01e to your computer and use it in GitHub Desktop.
Hi @SonamSangpoLama, I think you want to check the contents of your y_train vector. There is too many classes in it. It can only be a number between 0 and 10:
The dataset consists of 10 genres i.e
Blues
Classical
Country
Disco
Hiphop
Jazz
Metal
Pop
Reggae
Rock
Hi @SonamSangpoLama, I think you want to check the contents of your y_train vector. There is too many classes in it. It can only be a number between 0 and 10:
The dataset consists of 10 genres i.e
Blues Classical Country Disco Hiphop Jazz Metal Pop Reggae Rock
Thank you for your kind response..
Can you explain me further. I cannot get it..How can I check y_train content..?
Hi @SonamSangpoLama,
Can you share what does the 'label' column look like in your dataset?
Maybe you took a dataset with too many classes. Can you share the output of this?:
data = pd.read_csv('data.csv')
display(data.head())
print(data['label'].unique())
I have just been trying to use the same code of above but I am getting error. I have just made tiny changes on file directory.
Extracting spec from audios
cmap = plt.get_cmap('inferno')
plt.figure(figsize=(10,10))
genres = 'blues classical country disco hiphop jazz metal pop reggae rock'.split()
for g in genres:
pathlib.Path(f'image_genres/{g}').mkdir(parents=True, exist_ok=True)
for filename in os.listdir(f'./genres/{g}'):
songname = f'./genres/{g}/{filename}'
y, sr = librosa.load(songname, mono=True, duration=5)
plt.specgram(y, NFFT=2048, Fs=2, Fc=0, noverlap=128, cmap=cmap, sides='default', mode='default', scale='dB');
plt.axis('off');
plt.savefig(f'image_genres/{g}/{filename[:-3].replace(".", "")}.png')
plt.clf()
extracting features from spect
header = 'filename chroma_stft rmse spectral_centroid spectral_bandwidth rolloff zero_crossing_rate'
for i in range(1, 21):
header += f' mfcc{i}'
header += ' label'
header = header.split()
writing to csv
file = open('data.csv', 'w', newline='')
with file:
writer = csv.writer(file)
writer.writerow(header)
genres = 'blues classical country disco hiphop jazz metal pop reggae rock'.split()
for g in genres:
for filename in os.listdir(f'./genres/{g}'):
songname = f'./genres/{g}/{filename}'
y, sr = librosa.load(songname, mono=True, duration=30)
chroma_stft = librosa.feature.chroma_stft(y=y, sr=sr)
spec_cent = librosa.feature.spectral_centroid(y=y, sr=sr)
spec_bw = librosa.feature.spectral_bandwidth(y=y, sr=sr)
rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)
zcr = librosa.feature.zero_crossing_rate(y)
mfcc = librosa.feature.mfcc(y=y, sr=sr)
to_append = f'{filename} {np.mean(chroma_stft)} {np.mean(spec_cent)} {np.mean(spec_bw)} {np.mean(rolloff)} {np.mean(zcr)}'
for e in mfcc:
to_append += f' {np.mean(e)}'
to_append += f' {g}'
file = open('data.csv', 'a', newline='')
with file:
writer = csv.writer(file)
writer.writerow(to_append.split())
reading csv
data = pd.read_csv('data.csv')
data.head()
standard scaler
scaler = StandardScaler()
X = scaler.fit_transform(np.array(data.iloc[:, :1], dtype = float))
What was the use of spectrogram images???
I wrote a easy to understand notebook based on FE ideas in this one:
https://github.com/jkotra/MusicGenreClassification/blob/master/MusicGenreClassification_FeatureEnsemble.ipynb
Take a look if this seems too complicated 😉
Hello @ndujar.
Could you please describe in more detail how to me predictions, namely the arrays that are displayed during prediction, turn into genres. I will be very grateful!
For this code, I am getting problem of "keras scratch graph"
history = model.fit(X_train, y_train, epochs=10, batch_size=32)
InvalidArgumentError: Received a label value of 996 which is outside the valid range of [0, 10). Label values: 807 996 153 945 283 178 816 976 923 648 129 22 944 439 34 979 288 994 321 483 810 830 215 736 324 138 308 796 473 824 206 627
[[node loss_7/dense_24_loss/sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_6597]
Function call stack:
keras_scratch_graph
CAN SOMEONE HELP ME TO SORT OUT THIS PROBLEM