简体   繁体   English

ValueError:conv2d 层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(无、400、50)

[英]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.

相关问题 ValueError:层“conv2d”的输入 0 与层不兼容:预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(28、28、1) - ValueError: Input 0 of layer "conv2d" is incompatible with the layer: expected min_ndim=4, found ndim=3. Full shape received: (28, 28, 1) ValueError:conv2d 层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(2240、70、3) - ValueError: Input 0 of layer conv2d is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (2240, 70, 3) ValueError:层 conv2d 的输入 0 与层不兼容:预期 ndim=4,发现 ndim=3。 收到的完整形状:[无,30,30] - ValueError: Input 0 of layer conv2d is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [None, 30, 30] ValueError:conv2d_46 层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:(无,64,64) - ValueError: Input 0 of layer conv2d_46 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 64, 64) ValueError: 层序列 9 的输入 0 与层不兼容:预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[无,无,无] - ValueError: Input 0 of layer sequential_9 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, None, None] ValueError:layersequential_1 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[无、256、256] - ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 256, 256] ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[None, 32, 32] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 32, 32] 层 conv1d_39 的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,64) - Input 0 of layer conv1d_39 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 64) 层 conv1d 的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,30) - Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 30) Keras Conv2D - ValueError:层序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3 - Keras Conv2D - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM