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










0












$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



enter image description here



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.










share|improve this question









New contributor




Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$
















    0












    $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



    enter image description here



    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.










    share|improve this question









    New contributor




    Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      0












      0








      0





      $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



      enter image description here



      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.










      share|improve this question









      New contributor




      Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $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



      enter image description here



      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






      share|improve this question









      New contributor




      Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Mar 21 at 17:20







      Eclairs













      New contributor




      Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Mar 21 at 16:22









      EclairsEclairs

      1




      1




      New contributor




      Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Eclairs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          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.









          draft saved

          draft discarded


















          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.









          draft saved

          draft discarded


















          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Tähtien Talli Jäsenet | Lähteet | NavigointivalikkoSuomen Hippos – Tähtien Talli

          Do these cracks on my tires look bad? The Next CEO of Stack OverflowDry rot tire should I replace?Having to replace tiresFishtailed so easily? Bad tires? ABS?Filling the tires with something other than air, to avoid puncture hassles?Used Michelin tires safe to install?Do these tyre cracks necessitate replacement?Rumbling noise: tires or mechanicalIs it possible to fix noisy feathered tires?Are bad winter tires still better than summer tires in winter?Torque converter failure - Related to replacing only 2 tires?Why use snow tires on all 4 wheels on 2-wheel-drive cars?