Skip to main content
deleted 77 characters in body
Source Link
Nicolas Gervais
  • 37k
  • 24
  • 125
  • 160

ValueError: Input 0 of layer sequential_50sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None[8, 22428, 224]28]

I'mI keep on getting this error. If I add (None, IMG_SIZE, IMG_SIZE, 1), I get this error. And if I remove (IMG_SIZE, IMG_SIZE, 1) 'none' I get compile time error. Others I saw having similiar issues with different reasons related to input shape. Any help would be highly apprceciatedappreciated. Thanks!

def convolutional_model():
    
    from keras.utils import to_categorical
    from keras.modelstensorflow importas Sequentialtf
    from keras.layers import Conv2D
(xtrain, ytrain), (xtest, ytest) from= kerastf.layers import MaxPooling2D
    from keras.layers import Dense
    from kerasdatasets.layers import Flatten
    from kerasmnist.optimizers import SGDload_data()
    from keras.preprocessing.image import ImageDataGenerator
   model from= tensorflowtf.keras.optimizers import RMSprop
    from keras.layers import Dropout
    from tensorflow import keras
    
    # create model
    model = Sequential()[
#     modeltf.add(keras.Input(shape=(None, IMG_SIZE, IMG_SIZE, 1)))
#     Convolutional layer 1 with 32 filters of kernel size[5,5] 
    modellayers.add(Conv2D(filters=32, kernel_size=(5, 5), strides=(116, 1)kernel_size=3, activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 1)))
#     Pooling layer 1 with pool size[2,2] and stride 2 
    modeltf.add(keras.layers.MaxPooling2D(pool_size=(2, 2), strides=(2, 2))pool_size=2)
    
#     Convolutional layer 2 with 64 filters of kernel size[5,5] 
    modeltf.add(keras.layers.Conv2D(64, (5, 5), strides=(132, 1)kernel_size=3, activation='relu'))
#  Pooling layer 2 with pool size[2,2] and stride 2 
    modeltf.add(keras.layers.MaxPooling2D(pool_size=(2, 2pool_size=2), strides=(2, 2)))

    modeltf.add(keras.layers.Flatten())
    ,
#     tf.keras.layers.Dense layer whose output size is fixed in the hyper parameter:(64, activation='relu'),
    modeltf.add(keras.layers.Dense(units=3210, activation='relu')activation='softmax')
    ])
#     Dropout layer with dropout probability 0.4 
    model.add(Dropoutcompile(0.4))


   loss='categorical_crossentropy', 
#     units is 2 because we have 2 classes to predict (cot or dog)optimizer='adam',
    model.add(Dense(units=2, activation='softmax'))
    
     # Compile modelmetrics='accuracy')
#   
history = model.compilefit(loss='binary_crossentropy'xtrain, optimizer='adam'ytrain, metrics=['accuracy'])
    
    # compile model
    model.compile(
             optimizer=RMSpropvalidation_data=(lr=0.001)xtest,
             loss='binary_crossentropy'ytest),
             metrics=['accuracy'])
    return model

fit model

history = model.fit(x_train, steps_per_epoch=len(x_train),
validation_data=x_test, validation_steps=len(x_test), epochs=3epochs=10, verbose=2batch_size=8)

ValueError: Input 0 of layer sequential_50 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 224, 224]

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [8, 28, 28]

ValueError: Input 0 of layer sequential_50 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 224, 224]

I'm keep on getting this error. If I add (None, IMG_SIZE, IMG_SIZE, 1), I get this error. And if I remove (IMG_SIZE, IMG_SIZE, 1) 'none' I get compile time error. Others I saw having similiar issues with different reasons. Any help would be highly apprceciated. Thanks!

def convolutional_model():
    
    from keras.utils import to_categorical
    from keras.models import Sequential
    from keras.layers import Conv2D
    from keras.layers import MaxPooling2D
    from keras.layers import Dense
    from keras.layers import Flatten
    from keras.optimizers import SGD
    from keras.preprocessing.image import ImageDataGenerator
    from tensorflow.keras.optimizers import RMSprop
    from keras.layers import Dropout
    from tensorflow import keras
    
    # create model
    model = Sequential()
#     model.add(keras.Input(shape=(None, IMG_SIZE, IMG_SIZE, 1)))
#     Convolutional layer 1 with 32 filters of kernel size[5,5] 
    model.add(Conv2D(filters=32, kernel_size=(5, 5), strides=(1, 1), activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 1)))
#     Pooling layer 1 with pool size[2,2] and stride 2 
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
    
#     Convolutional layer 2 with 64 filters of kernel size[5,5] 
    model.add(Conv2D(64, (5, 5), strides=(1, 1), activation='relu'))
#  Pooling layer 2 with pool size[2,2] and stride 2 
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))

    model.add(Flatten())
    
#     Dense layer whose output size is fixed in the hyper parameter: 
    model.add(Dense(units=32, activation='relu'))
    
#     Dropout layer with dropout probability 0.4 
    model.add(Dropout(0.4))


    
#     units is 2 because we have 2 classes to predict (cot or dog)
    model.add(Dense(units=2, activation='softmax'))
    
     # Compile model
#     model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    
    # compile model
    model.compile(
             optimizer=RMSprop(lr=0.001),
             loss='binary_crossentropy',
             metrics=['accuracy'])
    return model

fit model

history = model.fit(x_train, steps_per_epoch=len(x_train),
validation_data=x_test, validation_steps=len(x_test), epochs=3, verbose=2)

ValueError: Input 0 of layer sequential_50 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 224, 224]

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [8, 28, 28]

I keep on getting this error related to input shape. Any help would be highly appreciated. Thanks!

import tensorflow as tf

(xtrain, ytrain), (xtest, ytest) = tf.keras.datasets.mnist.load_data()

model = tf.keras.Sequential([
    tf.keras.layers.Conv2D(16, kernel_size=3, activation='relu'),
    tf.keras.layers.MaxPooling2D(pool_size=2),
    tf.keras.layers.Conv2D(32, kernel_size=3, activation='relu'),
    tf.keras.layers.MaxPooling2D(pool_size=2),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
    ])

model.compile(loss='categorical_crossentropy', 
              optimizer='adam',
              metrics='accuracy')

history = model.fit(xtrain, ytrain,
                    validation_data=(xtest, ytest),
                    epochs=10, batch_size=8)

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [8, 28, 28]

deleted 77 characters in body
Source Link
Nicolas Gervais
  • 37k
  • 24
  • 125
  • 160
Source Link

ValueError: Input 0 of layer sequential_50 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 224, 224]

I'm keep on getting this error. If I add (None, IMG_SIZE, IMG_SIZE, 1), I get this error. And if I remove (IMG_SIZE, IMG_SIZE, 1) 'none' I get compile time error. Others I saw having similiar issues with different reasons. Any help would be highly apprceciated. Thanks!

def convolutional_model():
    
    from keras.utils import to_categorical
    from keras.models import Sequential
    from keras.layers import Conv2D
    from keras.layers import MaxPooling2D
    from keras.layers import Dense
    from keras.layers import Flatten
    from keras.optimizers import SGD
    from keras.preprocessing.image import ImageDataGenerator
    from tensorflow.keras.optimizers import RMSprop
    from keras.layers import Dropout
    from tensorflow import keras
    
    # create model
    model = Sequential()
#     model.add(keras.Input(shape=(None, IMG_SIZE, IMG_SIZE, 1)))
#     Convolutional layer 1 with 32 filters of kernel size[5,5] 
    model.add(Conv2D(filters=32, kernel_size=(5, 5), strides=(1, 1), activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 1)))
#     Pooling layer 1 with pool size[2,2] and stride 2 
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
    
#     Convolutional layer 2 with 64 filters of kernel size[5,5] 
    model.add(Conv2D(64, (5, 5), strides=(1, 1), activation='relu'))
#  Pooling layer 2 with pool size[2,2] and stride 2 
    model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))

    model.add(Flatten())
    
#     Dense layer whose output size is fixed in the hyper parameter: 
    model.add(Dense(units=32, activation='relu'))
    
#     Dropout layer with dropout probability 0.4 
    model.add(Dropout(0.4))


    
#     units is 2 because we have 2 classes to predict (cot or dog)
    model.add(Dense(units=2, activation='softmax'))
    
    # Compile model
#     model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    
    # compile model
    model.compile(
             optimizer=RMSprop(lr=0.001),
             loss='binary_crossentropy',
             metrics=['accuracy'])
    return model

enter image description here

fit model

history = model.fit(x_train, steps_per_epoch=len(x_train),
validation_data=x_test, validation_steps=len(x_test), epochs=3, verbose=2)

ValueError: Input 0 of layer sequential_50 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 224, 224]