为什么在培训CNN时准确度不会提高?

问题描述 投票:1回答:1

我一直在努力培训CNN来识别流派。使用(小)FMA数据集,每个30秒的歌曲片段已经使用librosa转换为mel谱图。反过来,这些光谱图已被转换为480x640x3矩阵(像素高度,像素宽度,RGB值),而这些矩阵又被切割成三个具有50%重叠的第二段,产生尺寸为480x64x3的最终输入矩阵。我写的网络旨在复制这篇(https://arxiv.org/pdf/1802.09697.pdf)论文中描述的网络。

因此,总共有7197个mel谱图作为输入,分成3个重叠,产生7197 * 19 = 136743个矩阵作为输入,800 * 19 = 15200个矩阵作为测试数据。网络有八种类型可供学习,标记为0-7。

训练时,即使在几个时期之后,准确度仍然低于0,125(相当于纯猜测(1/8))。那么我做错了什么?

import keras
#from keras.datasets import mnist
from keras.models import load_model
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
import numpy as np

#THIS ARCHITECTURE IS TAKEN FROM: https://arxiv.org/pdf/1802.09697.pdf
#3s with 50% overlap

batch_size = 64 #The set of examples used in one iteration (that is, one gradient update) of model training.
num_classes = 8 #1,2,3,4,5,6,7,8
epochs = 20   

# input image dimensions
img_rows, img_cols = 480, 64  #480x640 pixlar

# the data, split between train and test sets

(x_train, y_train) = (np.load('x_data_train_3s.npy'), np.load('y_data_train_3s.npy'))
(x_test, y_test) = (np.load('x_data_test_3s.npy'), np.load('y_data_test_3s.npy'))

x_train = x_train.reshape(136743,480,64,3) #this network accepts only 4-dim vector, so we reshape it. the last argument=grayscale. for RGB use 3. 
x_test = x_test.reshape(15200,480,64,3)

print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')

# convert class vectors to binary class matrices
#y_train = y_train -5    #otherwise error in np_utils.py
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

#IMAGE DIMENSIONS
model = Sequential()
model.add(Conv2D(64, kernel_size=(3, 3),   #first layer
                 activation='relu',
                 input_shape=(480,64,3)))
model.add(MaxPooling2D(pool_size=(2, 2))) #second layer, pooling
model.add(Conv2D(64, (3, 5), activation='relu')) #third layer
model.add(Dropout(0.25))     #dropout makes sure there is no overfitting, randomly switches of some neurons
model.add(MaxPooling2D(pool_size=(2, 4))) #fifth layer, pooling
model.add(Flatten())
model.add(Dense(128, activation ='relu'))
model.add(Dense(num_classes, activation='softmax'))


model.compile(loss=keras.losses.categorical_crossentropy,   #compile the model with cross entropy loss function
              optimizer=keras.optimizers.Adadelta(),
              metrics=['accuracy'])

model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          verbose=1,
          validation_data=(x_test, y_test))
score = model.evaluate(x_test, y_test, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])

model.save('genres.h5')

正如上面链接的论文,我预计准确度大约为0.7,但我只得到0.125。这有什么不对?

tensorflow keras conv-neural-network
1个回答
2
投票

1.由于您的数据集相对较小。您必须进行数据扩充才能获得更好的结果。 2.确定合适的批量大小也是获得更好结果的好因素。批量大小32模型和批量大小64模型可以不同地产生验证准确度。 3.减少正则化参数也有助于获得更好的结果。

你有5个池大小为64的图像到3 * 3大小:第一层池是21 * 21 * 64第五层池是64图像到2 * 4

这是相当多的汇集。尝试5 * 5转换层,最大池2 * 2块然后在完全连接层之前退出。如果提及的步骤没有改善您的结果,那么请使用Tensorflow的高级API来深入了解深度学习库。

© www.soinside.com 2019 - 2024. All rights reserved.