我正在进行声音分类任务,我将二维声谱图数据重塑为(1,139 * 139),将其存储到列表中。有5700个这样的训练向量。当我将其提供给InceptionV3模型时,出现错误-“ 检查输入时发生错误:预期inception_v3_input具有4个维度,但数组的形状为(5700,19321)”。我不知道应该在大小或任何地方进行什么更改。请对此进行指导,以便我可以继续进行。 TIA。
代码如下: => 数据列表是包含* .wav文件中的8000个样本的列表。
specX = np.zeros([len(dataList), 19321]) # storing all the spectrogram here.
xindex = 0
for x in dataList:
work = matplotlib.mlab.specgram(x)[0] #generation of spectrogram
worka = work[0:84,0:84] #taking square bins out of rectangular bins of 129 * 85 from each sample
worka = scipy.misc.imresize(worka,[139,139]) #making the image size 139 * 139
print("worka.shape : ", worka.shape)
worka = np.reshape(worka,[1,19321]) #resizing it to fit it into the specX.
specX[xindex,:] = worka
xindex +=1
#Taking 5700 samples as training data and rest is divided into test + validation
split1 = specX.shape[0] - specX.shape[0]/20
split1 = int(split1)
#print("split1 : ", split1)
split2 = (specX.shape[0] - split1) / 2
split2 = int(split2)
#print("split2 : ", split2)
formatToUse = specX
Data = np.concatenate((formatToUse,Ys),axis=1)
DataShuffled = np.random.permutation(Data)
newX,newY = np.hsplit(DataShuffled,[-1])
trainX,otherX = np.split(newX,[split1])
trainYa,otherY = np.split(newY,[split1])
valX, testX = np.split(otherX,[split2])
valYa,testYa = np.split(otherY,[split2])
trainY = oneHotIt(trainYa)
testY = oneHotIt(testYa)
valY = oneHotIt(valYa)
return classes,trainX,trainYa,valX,valYa,testX,testYa
现在,当我尝试将其提供给该模型时:
def googleNet(classes):
inception_conv = InceptionV3(include_top=False, weights='imagenet', input_shape=(139, 139, 3))
# Freeze the layers except the last 1 layers
for layer in inception_conv.layers[:-1]:
layer.trainable = False
# Check the trainable status of the individual layers
for layer in inception_conv.layers:
print(layer, layer.trainable)
# Create the model
model = models.Sequential()
# Add the vgg convolutional base model
model.add(inception_conv)
# Add new layers
model.add(layers.Flatten(input_shape=inception_conv.output_shape[1:]))
model.add(layers.Dense(1024, activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(classes, activation='softmax'))
return model
myModel = googleNet(classes)
myModel.compile(optimizer='rmsprop', loss='categorical_crossentropy')
history = myModel.fit(np.array(trainX), np.array(trainYa),
validation_data=(np.array(valX), np.array(valYa)),
verbose=1,
batch_size=batchSize,
epochs=iterations)