简体   繁体   English

层“max_pooling2d_30”的输入0与层不兼容:预期ndim=4,发现ndim=5

[英]Input 0 of layer "max_pooling2d_30" is incompatible with the layer: expected ndim=4, found ndim=5

I'm just starting to approach ml, and I'm trying to train a model on an image dataset obtained from directories of images using tf.keras.utils.image_dataset_from_directory (then pickling it), so that it can predict which letter is fingerspelled in the image.我刚刚开始接近 ml,我正在尝试在使用 tf.keras.utils.image_dataset_from_directory 从图像目录获得的图像数据集上训练模型(然后对其进行酸洗),以便它可以预测哪个字母是手指拼写的在图像中。

So, this is how I unpickle my sets of data:所以,这就是我解开我的数据集的方式:

#PICKLE LOAD

#TRAIN
  #images
with open('x_train.pkl', 'rb') as x_train_pickle:
  x_train_data = pickle.load(x_train_pickle)
  #labels
with open('y_train.pkl', 'rb') as y_train_pickle:
  y_train_data = pickle.load(y_train_pickle)

#VALIDATION
with open('x_val.pkl', 'rb') as x_val_pickle:
  x_val_data = pickle.load(x_val_pickle)

with open('y_val.pkl', 'rb') as y_val_pickle:
  y_val_data = pickle.load(y_val_pickle)

#TEST
with open('x_test.pkl', 'rb') as x_test_pickle:
  x_test_data = pickle.load(x_test_pickle)

with open('y_test.pkl', 'rb') as y_test_pickle:
  y_test_data = pickle.load(y_test_pickle)

You are giving 5D data to Conv2d instead of 4D.So, either your data should be in the shape (batch_size*32, 180, 180, 3) or You can use the TimeDistributed layer wrapper to apply the same convolution layer on all the images in the 5D tensor.您将 5D 数据提供给 Conv2d 而不是 4D。因此,您的数据应为 (batch_size*32, 180, 180, 3) 形状,或者您可以使用 TimeDistributed 层包装器在所有图像上应用相同的卷积层在 5D 张量中。 For example:例如:

model = Sequential()
model.add(tf.keras.layers.TimeDistributed(tf.keras.layers.Conv2D(32, 3, activation='relu')))

model.summary()

暂无
暂无

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

相关问题 Keras 尺寸错误 - (层“max_pooling2d”的输入 0 与层不兼容:预期 ndim=4,发现 ndim=6。) - Keras Dimension error - (Input 0 of layer "max_pooling2d" is incompatible with the layer: expected ndim=4, found ndim=6.) ValueError: 层 max_pooling1d 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=4。 收到的完整形状:(无、128、1、32) - ValueError: Input 0 of layer max_pooling1d is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 128, 1, 32) 层 max_pooling2d 的输入 0 与层不兼容:预期 ndim=4,发现 ndim=5。 收到完整形状:[无、4、10、8、32] - Input 0 of layer max_pooling2d is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [None, 4, 10, 8, 32] 输入0与图层global_average_pooling2d_4不兼容:预期ndim = 4,发现ndim = 2错误 - Input 0 is incompatible with layer global_average_pooling2d_4: expected ndim=4, found ndim=2 error 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:global_average_pooling2d 层的输入 0 与该层不兼容:预期 ndim=4,发现 ndim=2。 收到的完整形状:[无,128] - ValueError: Input 0 of layer global_average_pooling2d is incompatible with the layer: expected ndim=4, found ndim=2. Full shape received: [None, 128] ValueError:层“max_pooling1d”的输入 0 与层不兼容:预期 ndim=3,发现 ndim=4。 收到完整形状:(无,51644、29、32) - ValueError: Input 0 of layer "max_pooling1d" is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 51644, 29, 32) ValueError:层“max_pooling2d”的输入 0 与层不兼容:预期 ndim=4,发现 ndim=5。 收到的完整形状:(无、3、51、39、32) - ValueError: Input 0 of layer "max_pooling2d" is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: (None, 3, 51, 39, 32) 层 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) 层“bidirectional_2”的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2 - Input 0 of layer "bidirectional_2" is incompatible with the layer: expected ndim=3, found ndim=2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM