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]