Python 预期inception_v3_输入有4个维度,但得到了具有形状的数组(570019321)
我正在进行声音分类任务,通过将二维谱图数据重新设置为(1139*139),将其存储到一个列表中。有5700个这样的训练向量。当我把它输入到inceptionV3模型时,我得到了一个错误--“检查输入时出错:预期inception\u v3\u输入有4个维度,但得到了具有形状的数组(570019321)”。我无法理解在尺寸或任何地方应该做什么改变。请在这方面给我指导,以便我可以据此进行。蒂亚 代码如下: =>datalist是包含从*.wav文件中提取的8000个样本的列表。Python 预期inception_v3_输入有4个维度,但得到了具有形状的数组(570019321),python,machine-learning,keras,Python,Machine Learning,Keras,我正在进行声音分类任务,通过将二维谱图数据重新设置为(1139*139),将其存储到一个列表中。有5700个这样的训练向量。当我把它输入到inceptionV3模型时,我得到了一个错误--“检查输入时出错:预期inception\u v3\u输入有4个维度,但得到了具有形状的数组(570019321)”。我无法理解在尺寸或任何地方应该做什么改变。请在这方面给我指导,以便我可以据此进行。蒂亚 代码如下: =>datalist是包含从*.wav文件中提取的8000个样本的列表。 specX = np
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)
Inception期望形状数据
(139、139、3)
,其中3表示通道(R、G、B);像在np中那样调整大小。重塑(worka[119321])
将不起作用,这正是错误消息告诉您的。谢谢您的回复。那么,这是否意味着使用相同的代码,我不能使用inceptionV3?如果您将输入图像重新设置为(139,139)
,并找到某种方法在所有3个通道中传递信息(不是很简单,但可能)