-
-
Save parulnith/7f8c174e6ac099e86f0495d3d9a4c01e to your computer and use it in GitHub Desktop.
can you send us loaction of your path. i am not getting the logic
header = 'filename chroma_stft spectral_centroid spectral_bandwidth rolloff zero_crossing_rate'
for i in range(1, 21):
header += f' mfcc{i} '
header += ' label '
header = header.split()
i have got syntax errror
how to fix the pblm??help me
File "", line 3
header += f' mfcc{i} '
^
SyntaxError: invalid syntax
In case any one having error with the rmse just include rmse = librosa.feature.rmse(y=y)
in the 4th block code.
@gjnehruceg33 are you using Python 3.6+? If not, you'll be seeing that syntax error.
You should be able to change header += f' mfcc{i} '
to header += ' mfcc{0} '.format(i)
and that should work on Python 2.
In case any one having error with the rmse just include
rmse = librosa.feature.rmse(y=y)
in the 4th block code.
Notice that after 0.6.3 version change librosa.feature.rmse
to librose.feature.rms
.
Nice work
How to make gui for this?
In case any one having error with the rmse just include
rmse = librosa.feature.rmse(y=y)
in the 4th block code.Notice that after 0.6.3 version change
librosa.feature.rmse
tolibrose.feature.rms
.
librosa.feature.rms <=
Where did you use those images, I just wanted to know are they just for visualization?
You extracted all spectrograms and saved them as figs, but you don't need them for training? Then, what was the point there?
You extracted all spectrograms and saved them as figs, but you don't need them for training? Then, what was the point there?
Hi @basriciftci, good question. Like I have mentioned in the article accompanying the code(https://towardsdatascience.com/music-genre-classification-with-python-c714d032f0d8), the purpose of this whole exercise was to help beginners understand the concept of working and understanding the audio files. Once the data has been extracted, they can use any algorithm of their choice to train it.
hello,
when i test on genres it work fine , when i test on my set of songs it did not work . I am using two type of songs , it read one type but did not read other part for example when print (y) : 000000000000000000000000000000000000 ... is the printed but 111111111111111111111 is missing . would you please solve this issue . thanks
Hi @parulnith. I am wondering have you any example where you used the Spectogram images for training the Neural network and classifying?
Hi @parulnith. I am wondering have you any example where you used the Spectogram images for training the Neural network and classifying?
Hi @DylanCarey94, did you manage to create a neural network using the spectogram images?
Hi there, I ran through the code and for the code block: np.argmax(predictions[0])
My result was 3. I noticed in the example that it is 8. Does this mean something is wrong with my model?
How can we start using this to pass it new songs to predict?
Hi @specpro30,
Just put replace the data in X_test with whatever features you extract from your new songs and you are good to go :)
Don't forget to scale before using the scaler
X_new = scaler.fit_transform(np.array(new_data, dtype = float))
predictions = model.predict(X_new)
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
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!
GTZAN dataset:
http://opihi.cs.uvic.ca/sound/genres.tar.gz