[英]ValueError: Input 0 of layer conv2d is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 400, 50)
I keep on getting this error related to the input shape.我不断收到与输入形状相关的错误。 Any help would be very appreciated.任何帮助将不胜感激。 Thank you!谢谢!
def deep_model():
model = Sequential()
model.add(keras.layers.Conv1D(filters=50, kernel_size=9, strides=1, padding='same',
batch_input_shape=(None, Length, 4), activation='relu'))
model.add(keras.layers.Conv2D(32, kernel_size =(9, 9), strides =(1, 1),
activation ='relu'))
model.add(MaxPooling2D(pool_size =(2, 2), strides =(2, 2)))
model.add(keras.layers.Conv2D(64, (9, 9), activation ='relu'))
model.add(MaxPooling2D(pool_size =(2, 2)))
model.add(Flatten())
model.add(Dense(100, activation ='relu'))
model.add(Dropout(0.3))
model.add(Dense(3, activation ='softmax'))
# training the model
model.compile(loss = keras.losses.categorical_crossentropy,
optimizer = keras.optimizers.SGD(lr = 0.01),
metrics =['accuracy'])
return model
x_train = x_train.reshape(-1, 400, 4)
raise ValueError('Input ' + str(input_index) + ' of layer ' + ValueError: Input 0 of layer conv2d is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 400, 50) raise ValueError('Input ' + str(input_index) + ' of layer ' + ValueError: Input 0 of layer conv2d is in compatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 400, 50)
I tried to reshape the x_train also but got this error:我也尝试重塑 x_train 但收到此错误:
x_train = x_train.reshape(-1, 400, 400, 4) ValueError: cannot reshape array of size 43200000 into shape (400,400,4) x_train = x_train.reshape(-1, 400, 400, 4) ValueError: 无法将大小为 43200000 的数组重塑为 (400,400,4)
I think you need the input shape to have an extra dimension.我认为你需要输入形状有一个额外的维度。 The reason your reshaping failed is because 400 * 400 * 4
is equal to 640000
and not 43200000
重塑失败的原因是400 * 400 * 4
等于640000
而不是43200000
This is how you would do it:你会这样做:
x_train = x_train[np.newaxis]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.