I am using pre-trained model GoogleNet for my first image classification application. While using Flatten, I am getting this error-
ValueError: The shape of the input to "Flatten" is not fully defined got
(None, None, 64). Make sure to pass a complete "input_shape" or
"batch_input_shape" argument to the first layer in your model.
I have searched a lot on internet but did not find the solution anywhere. I would appreciate if anyone can help me with this.
Below is my code.
train_datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
test_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
'dir_path',
target_size=(500, 500),
batch_size=batch_size,
class_mode='categorical')
validation_generator = test_datagen.flow_from_directory(
'dir_path',
target_size=(500, 500),
batch_size=batch_size,
class_mode='categorical')
base_model = InceptionV3(weights='imagenet', include_top=False)
x = base_model.output
x = Conv2D(32, (3, 3), use_bias=True, activation='relu', input_shape=
(500,500,3)) (x) #line2
x = MaxPooling2D(pool_size=(2, 2))(x)
x = Conv2D(64, (3, 3), activation='relu') (x) #line3
x = Flatten()(x)
x = Dense(batch_size, activation='relu')(x) #line1
x = (Dropout(0.5))(x)
predictions = Dense(num_classes, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=predictions)
You should move your input shape from your first Conv2D layer to your base model like this:
base_model = InceptionV3(weights='imagenet', input_shape=(500,500,3), include_top=False)
x = base_model.output
x = Conv2D(32, (3, 3), use_bias=True, activation='relu', ) (x)
...