Skip to content

Adding data_augmentation layer causes errors with model_1 in 05_transfer_learning #683

@ilsid

Description

@ilsid

Discussed in #680

Originally posted by MikaATuomaala December 17, 2024
Hi,

I have problems with "05_transfer_learning". Following code used for model_1:

input_shape = (224, 224, 3)
base_model = tf.keras.applications.EfficientNetV2B0(include_top=False)
base_model.trainable = False

inputs = layers.Input(shape=input_shape, name="input_layer")

x = data_augmentation(inputs, training=True)

where data_augmentation is defined as follows:

data_augmentation = keras.Sequential([
    layers.RandomFlip("horizontal"),
    layers.RandomRotation(0.2),
    layers.RandomZoom(0.2),
    layers.RandomHeight(0.2),
    layers.RandomHeight(0.2),
    # preprocessing.rescasle(1./255) # Resnet50v2 may need this
], name = "data_augmentation")

produces following error:

Input 0 of layer "functional_1" is incompatible with the layer: expected shape=(None, 384, 512, 3), found shape=(None, 224, 224, 3)

Arguments received by Sequential.call():
  • args=('<KerasTensor shape=(None, 224, 224, 3), dtype=float32, sparse=False, name=input_layer>',)
  • kwargs={'training': 'True', 'mask': 'None'}

As far as I can tell, the code is same as in the updated course notes. And I have tried to copy-paste from the updated notes, but that doesn't seem to make any difference.

Tensorflow version is 2.17.1 and the runtime type is T4 GPU

Any ideas what could be causing this? And better yet, how to fix it?

Thanks,
-Mika

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions