CNN validation accuracy not improving - spectrogram2019 Community Moderator ElectionImproving Naive Bayes accuracy for text classificationThe validation loss < training loss and validation accuracy < training accuracyvalidation/training accuracy and overfittingLoss for CNN decreases and settles but training accuracy does not improveKeras: Prediction performance does not match accuracyHow to interpret a drastic accuracy loss while training a neuronal net (CNN)?Value error in Merging two different models in kerasValue of loss and accuracy does not change over EpochsSteps taking too long to completeOptimization based on validation and not training
Implement the Thanos sorting algorithm
Finding all intervals that match predicate in vector
quarter to five p.m
Using parameter substitution on a Bash array
Coordinate position not precise
Displaying the order of the columns of a table
What is difference between behavior and behaviour
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Why Were Madagascar and New Zealand Discovered So Late?
Is exact Kanji stroke length important?
What's a natural way to say that someone works somewhere (for a job)?
Valid Badminton Score?
Your magic is very sketchy
Mapping a list into a phase plot
Why "be dealt cards" rather than "be dealing cards"?
Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past
Was the picture area of a CRT a parallelogram (instead of a true rectangle)?
Is there an Impartial Brexit Deal comparison site?
Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?
Modify casing of marked letters
What is the opposite of 'gravitas'?
Can I convert a rim brake wheel to a disc brake wheel?
How can I replace every global instance of "x[2]" with "x_2"
when is out of tune ok?
CNN validation accuracy not improving - spectrogram
2019 Community Moderator ElectionImproving Naive Bayes accuracy for text classificationThe validation loss < training loss and validation accuracy < training accuracyvalidation/training accuracy and overfittingLoss for CNN decreases and settles but training accuracy does not improveKeras: Prediction performance does not match accuracyHow to interpret a drastic accuracy loss while training a neuronal net (CNN)?Value error in Merging two different models in kerasValue of loss and accuracy does not change over EpochsSteps taking too long to completeOptimization based on validation and not training
$begingroup$
I am new to Machine Learning. So, for a project I am trying to classify instruments in .wav file. The dataset I am using is IRMAS.
Dataset contains 11 classes of instruments with recordings in 16 bit stereo wav format sampled at 44.1kHz of 3s for each instrument.
I am converting all audio files to spectrograms for CNN using
walk.py
import os
import sys
from spectrogram import convert_to_spectrogram as cts
current_path = sys.argv[1]
destination_path = sys.argv[2]
i = 1
for file in os.listdir(current_path):
current_file = os.path.join(current_path, file)
# cts(current_file, destination_path, os.path.splitext(file)[0]) # has problems with filenames having '.'
cts(current_file, destination_path, str(i)) # if dont need same file name will start from 1 to number of files
i += 1
spectrogram.py
import librosa
import librosa.display
import numpy as np
import os
def convert_to_spectrogram(filepath, filedest, filename):
y, sr = librosa.load(filepath)
librosa.feature.melspectrogram(y=y, sr=sr)
D = np.abs(librosa.stft(y, hop_length = 300))**2
S = librosa.feature.melspectrogram(S=D)
# Passing through arguments to the Mel filters
S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=256,
fmax=8000)
import matplotlib.pyplot as plt
plt.figure(figsize=(10,4) , frameon=False)
librosa.display.specshow(librosa.power_to_db(S,
ref=np.max),
y_axis='mel', fmax=8000,
x_axis='time')
plt.gca().set_axis_off()
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0,
hspace = 0, wspace = 0)
filename = filename + "1.jpg"
plt.savefig(os.path.join(filedest, filename))
This gives me spectrogram for all the audio files in the dataset.
Using this CNN model
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.layers import Dropout
from keras.models import model_from_json
from keras.models import load_model
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (128, 128, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Flatten())
classifier.add(Dense(units = 32, activation = 'relu'))
classifier.add(Dense(units = 11, activation = 'softmax'))
classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('dataset/training_set',
target_size = (128, 128),
batch_size = 128,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('dataset/test_set',
target_size = (128, 128),
batch_size = 64,
class_mode = 'categorical')
classifier.fit_generator(training_set,
steps_per_epoch = 1000,
epochs = 10,
validation_data = test_set,
validation_steps = 500)
The accuracy I get is pretty good but val_acc is around 0.2 ~ 0.22
I want to improve the val_acc for this.
After searching on the net I got to know its overfitting and tried adding dropout but that didn't help.
keras cnn accuracy
New contributor
$endgroup$
add a comment |
$begingroup$
I am new to Machine Learning. So, for a project I am trying to classify instruments in .wav file. The dataset I am using is IRMAS.
Dataset contains 11 classes of instruments with recordings in 16 bit stereo wav format sampled at 44.1kHz of 3s for each instrument.
I am converting all audio files to spectrograms for CNN using
walk.py
import os
import sys
from spectrogram import convert_to_spectrogram as cts
current_path = sys.argv[1]
destination_path = sys.argv[2]
i = 1
for file in os.listdir(current_path):
current_file = os.path.join(current_path, file)
# cts(current_file, destination_path, os.path.splitext(file)[0]) # has problems with filenames having '.'
cts(current_file, destination_path, str(i)) # if dont need same file name will start from 1 to number of files
i += 1
spectrogram.py
import librosa
import librosa.display
import numpy as np
import os
def convert_to_spectrogram(filepath, filedest, filename):
y, sr = librosa.load(filepath)
librosa.feature.melspectrogram(y=y, sr=sr)
D = np.abs(librosa.stft(y, hop_length = 300))**2
S = librosa.feature.melspectrogram(S=D)
# Passing through arguments to the Mel filters
S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=256,
fmax=8000)
import matplotlib.pyplot as plt
plt.figure(figsize=(10,4) , frameon=False)
librosa.display.specshow(librosa.power_to_db(S,
ref=np.max),
y_axis='mel', fmax=8000,
x_axis='time')
plt.gca().set_axis_off()
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0,
hspace = 0, wspace = 0)
filename = filename + "1.jpg"
plt.savefig(os.path.join(filedest, filename))
This gives me spectrogram for all the audio files in the dataset.
Using this CNN model
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.layers import Dropout
from keras.models import model_from_json
from keras.models import load_model
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (128, 128, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Flatten())
classifier.add(Dense(units = 32, activation = 'relu'))
classifier.add(Dense(units = 11, activation = 'softmax'))
classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('dataset/training_set',
target_size = (128, 128),
batch_size = 128,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('dataset/test_set',
target_size = (128, 128),
batch_size = 64,
class_mode = 'categorical')
classifier.fit_generator(training_set,
steps_per_epoch = 1000,
epochs = 10,
validation_data = test_set,
validation_steps = 500)
The accuracy I get is pretty good but val_acc is around 0.2 ~ 0.22
I want to improve the val_acc for this.
After searching on the net I got to know its overfitting and tried adding dropout but that didn't help.
keras cnn accuracy
New contributor
$endgroup$
add a comment |
$begingroup$
I am new to Machine Learning. So, for a project I am trying to classify instruments in .wav file. The dataset I am using is IRMAS.
Dataset contains 11 classes of instruments with recordings in 16 bit stereo wav format sampled at 44.1kHz of 3s for each instrument.
I am converting all audio files to spectrograms for CNN using
walk.py
import os
import sys
from spectrogram import convert_to_spectrogram as cts
current_path = sys.argv[1]
destination_path = sys.argv[2]
i = 1
for file in os.listdir(current_path):
current_file = os.path.join(current_path, file)
# cts(current_file, destination_path, os.path.splitext(file)[0]) # has problems with filenames having '.'
cts(current_file, destination_path, str(i)) # if dont need same file name will start from 1 to number of files
i += 1
spectrogram.py
import librosa
import librosa.display
import numpy as np
import os
def convert_to_spectrogram(filepath, filedest, filename):
y, sr = librosa.load(filepath)
librosa.feature.melspectrogram(y=y, sr=sr)
D = np.abs(librosa.stft(y, hop_length = 300))**2
S = librosa.feature.melspectrogram(S=D)
# Passing through arguments to the Mel filters
S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=256,
fmax=8000)
import matplotlib.pyplot as plt
plt.figure(figsize=(10,4) , frameon=False)
librosa.display.specshow(librosa.power_to_db(S,
ref=np.max),
y_axis='mel', fmax=8000,
x_axis='time')
plt.gca().set_axis_off()
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0,
hspace = 0, wspace = 0)
filename = filename + "1.jpg"
plt.savefig(os.path.join(filedest, filename))
This gives me spectrogram for all the audio files in the dataset.
Using this CNN model
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.layers import Dropout
from keras.models import model_from_json
from keras.models import load_model
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (128, 128, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Flatten())
classifier.add(Dense(units = 32, activation = 'relu'))
classifier.add(Dense(units = 11, activation = 'softmax'))
classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('dataset/training_set',
target_size = (128, 128),
batch_size = 128,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('dataset/test_set',
target_size = (128, 128),
batch_size = 64,
class_mode = 'categorical')
classifier.fit_generator(training_set,
steps_per_epoch = 1000,
epochs = 10,
validation_data = test_set,
validation_steps = 500)
The accuracy I get is pretty good but val_acc is around 0.2 ~ 0.22
I want to improve the val_acc for this.
After searching on the net I got to know its overfitting and tried adding dropout but that didn't help.
keras cnn accuracy
New contributor
$endgroup$
I am new to Machine Learning. So, for a project I am trying to classify instruments in .wav file. The dataset I am using is IRMAS.
Dataset contains 11 classes of instruments with recordings in 16 bit stereo wav format sampled at 44.1kHz of 3s for each instrument.
I am converting all audio files to spectrograms for CNN using
walk.py
import os
import sys
from spectrogram import convert_to_spectrogram as cts
current_path = sys.argv[1]
destination_path = sys.argv[2]
i = 1
for file in os.listdir(current_path):
current_file = os.path.join(current_path, file)
# cts(current_file, destination_path, os.path.splitext(file)[0]) # has problems with filenames having '.'
cts(current_file, destination_path, str(i)) # if dont need same file name will start from 1 to number of files
i += 1
spectrogram.py
import librosa
import librosa.display
import numpy as np
import os
def convert_to_spectrogram(filepath, filedest, filename):
y, sr = librosa.load(filepath)
librosa.feature.melspectrogram(y=y, sr=sr)
D = np.abs(librosa.stft(y, hop_length = 300))**2
S = librosa.feature.melspectrogram(S=D)
# Passing through arguments to the Mel filters
S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=256,
fmax=8000)
import matplotlib.pyplot as plt
plt.figure(figsize=(10,4) , frameon=False)
librosa.display.specshow(librosa.power_to_db(S,
ref=np.max),
y_axis='mel', fmax=8000,
x_axis='time')
plt.gca().set_axis_off()
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0,
hspace = 0, wspace = 0)
filename = filename + "1.jpg"
plt.savefig(os.path.join(filedest, filename))
This gives me spectrogram for all the audio files in the dataset.
Using this CNN model
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.layers import Dropout
from keras.models import model_from_json
from keras.models import load_model
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (128, 128, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Dropout(0.5))
classifier.add(Flatten())
classifier.add(Dense(units = 32, activation = 'relu'))
classifier.add(Dense(units = 11, activation = 'softmax'))
classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('dataset/training_set',
target_size = (128, 128),
batch_size = 128,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('dataset/test_set',
target_size = (128, 128),
batch_size = 64,
class_mode = 'categorical')
classifier.fit_generator(training_set,
steps_per_epoch = 1000,
epochs = 10,
validation_data = test_set,
validation_steps = 500)
The accuracy I get is pretty good but val_acc is around 0.2 ~ 0.22
I want to improve the val_acc for this.
After searching on the net I got to know its overfitting and tried adding dropout but that didn't help.
keras cnn accuracy
keras cnn accuracy
New contributor
New contributor
edited Mar 21 at 17:20
Eclairs
New contributor
asked Mar 21 at 16:22
EclairsEclairs
1
1
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Eclairs is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47747%2fcnn-validation-accuracy-not-improving-spectrogram%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Eclairs is a new contributor. Be nice, and check out our Code of Conduct.
Eclairs is a new contributor. Be nice, and check out our Code of Conduct.
Eclairs is a new contributor. Be nice, and check out our Code of Conduct.
Eclairs is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47747%2fcnn-validation-accuracy-not-improving-spectrogram%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown