mrdbourke / tensorflow-deep-learning

All course materials for the Zero to Mastery Deep Learning with TensorFlow course.
https://dbourke.link/ZTMTFcourse
MIT License
5.14k stars 2.53k forks source link

InvalidArgumentError: Graph execution error: Video 136, Model_10 #383

Open kelixirr opened 2 years ago

kelixirr commented 2 years ago

My Code Of The Model After Data Augmentation. Model cloning was not working on my TensorFlow version for unknown reasons so I used this

model_10 = Sequential([
 Conv2D(10, 3, input_shape=(224, 224, 3)),
 Activation(activation='relu'),
 Conv2D(10, 3, activation='relu'),
 MaxPool2D(),
 Conv2D(10, 3, activation='relu'),
 Conv2D(10, 3, activation='relu'),
 MaxPool2D(),
 Flatten(),
 Dense(10, activation="softmax")                     
])

model_10.compile(loss='categorical_crossentropy',
                 optimizer=tf.keras.optimizers.Adam(),
                 metrics=['accuracy'])

history_10 = model_10.fit(train_data_augmented, 
                          epochs=5, 
                          steps_per_epoch=len(train_data_augmented),
                          validation_data=test_data,
                          validation_steps=len(test_data))

Error Message

input to reshape is a tensor with 9412800 values, but the requested shape requires a multiple of 28090
[[{{node sequential_9/flatten_9/Reshape}}]] [Op:__inference_train_function_20412]
catbears commented 2 years ago

@kelixirr Used this code, because copying also didn't work for me:

train_datgen_augmented = ImageDataGenerator(rescale=1/255.,
                                           rotation_range=0.55,
                                           zoom_range=0.2,
                                           width_shift_range=0.1,
                                           height_shift_range=0.1,
                                           horizontal_flip=True)

train_datgen_augmented = train_datgen_augmented.flow_from_directory(train_dir,
                                        target_size=(244, 244),
                                        batch_size=32,
                                        class_mode="categorical")

model_10 = Sequential([
    Conv2D(10, 3, input_shape=(224, 224, 3)),
    Activation(activation="relu"),
    Conv2D(10, 3, activation="relu"),
    MaxPool2D(),
    Conv2D(10, 3, activation="relu"),
    Conv2D(10, 3, activation="relu"),
    MaxPool2D(),
    Flatten(),
    Dense(10, activation="softmax")
], "model_10")

model_10.compile(loss="categorical_crossentropy",
               optimizer=Adam(),
               metrics=["accuracy"])

history_10 = model_10.fit(train_data_augmented,
                       epochs=5,
                       steps_per_epoch=len(train_data_augmented),
                       validation_data=test_data,
                       validation_steps=len(test_data))
mrdbourke commented 2 years ago

Hi @kelixirr, did you manage to fix your error?

It looks like the input shapes to your data are off, I'd inspect the shapes of the data going into the model and see if there are mismatches.

And I'd also make sure the input and output shapes of each layer in your architecture line up.