简体   繁体   中英

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.

#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. For example:

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

model.summary()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Keras Dimension error - (Input 0 of layer "max_pooling2d" is incompatible with the layer: expected ndim=4, found ndim=6.) 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) 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] Input 0 is incompatible with layer global_average_pooling2d_4: expected ndim=4, found ndim=2 error ValueError: Input 0 of layer conv2d is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [None, 30, 30] 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: 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: 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) Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 30) Input 0 of layer "bidirectional_2" is incompatible with the layer: expected ndim=3, found ndim=2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM