简体   繁体   English

层序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=2。 收到的完整形状:(无,1)

[英]Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (None, 1)

I am trying to get the prediction of my model我试图得到我的 model 的预测

prediction = model.predict(validation_names)
print(prediction)

but I get the following error:但我收到以下错误:

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (None, 1)

I understand that this is due to the fact that the model accepts data of dimension 4我知道这是因为 model 接受维度 4 的数据

Model: Model:

model = tf.keras.models.Sequential([

          tf.keras.layers.Conv2D(16, (3,3), activation = 'relu', 
                                        input_shape = (300, 300, 3)),
          tf.keras.layers.MaxPooling2D(2,2),

          tf.keras.layers.Conv2D(32, (3,3), activation = 'relu'),
          tf.keras.layers.MaxPooling2D(2,2),

          tf.keras.layers.Conv2D(64, (3,3), activation = 'relu'),
          tf.keras.layers.MaxPooling2D(2,2),

          tf.keras.layers.Conv2D(64, (3,3), activation = 'relu'),
          tf.keras.layers.MaxPooling2D(2,2),

          tf.keras.layers.Flatten(),
          tf.keras.layers.Dense(512, activation = 'relu'),

          tf.keras.layers.Dense(3, activation = 'softmax')
])

How can I process the prediction data to solve this problem?如何处理预测数据来解决这个问题?

Conv2D expects 4+D tensor with shape: batch_shape + (channels, rows, cols) if data_format='channels_first' or 4+D tensor with shape: batch_shape + (rows, cols, channels) if data_format='channels_last' Conv2D 期望4+D tensor with shape: batch_shape + (channels, rows, cols) if data_format='channels_first' or 4+D tensor with shape: batch_shape + (rows, cols, channels) if data_format='channels_last'

Working sample code:工作示例代码:

# The inputs are 28x28 RGB images with `channels_last` and the batch
# size is 4.
import tensorflow as tf
input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv2D(2, 3, activation='relu', input_shape=input_shape[1:])(x)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError: 层顺序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=2。 收到完整形状:[无,1] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1] Keras 层顺序调谐器输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,216) - Keras Tuner Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 216) ValueError:layersequential_5 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=2。 收到的完整形状:[无,953] - ValueError: Input 0 of layer sequential_5 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 953] ValueError:顺序层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=2。 收到完整形状:[无,2584] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 2584] ValueError:layersequential_32 的输入 0 与 layer 不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:[无,256] - ValueError: Input 0 of layer sequential_32 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: [None, 256] ValueError:layersequential_4 的输入 0 与 layer 不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,5000) - ValueError: Input 0 of layer sequential_4 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 5000) ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(10, 24) - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (10, 24) ValueError: 层序贯_1 的输入 0 与层不兼容: : 预期 min_ndim=4,发现 ndim=2。 收到的完整形状:(32768, 1) - ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (32768, 1) 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] 层 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)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM