Chane the inception 4 shape

I downloaded the inception 4 from the following GitHub, and I did many trails to change the input_shape, however getting always error, would you please assist me of doing so,


Hi @FALAH_FAKHRI, The error occurs only when you try pass the input shape less than (299,299,3), because the model architecture is designed to work with a minimum input size of (299, 299, 3).I have tested with input shape (320,320,3) and (512,512,3) and i did not face any error.

If we define the model with input_shape less than (299,299,3) the input dimensions is becoming too small after going through the multiple layers of the model, and is causing an issue with the AveragePooling2D layer. Thank You.

1 Like

Thanks a lot for the informative information. May I ask you how it’s possible to make this model trainable = False or trainable = true, and then change the architecture, for instance:

model.trainable = True

# Freeze all layers except for the
for layer in model.layers[:-10]:
  layer.trainable = False

Similar to

model_ince3 = tf.keras.applications.inception_v3.InceptionV3(
    input_shape=(75, 75, 3),

I’d ask if you like about the possibility of altering the model architecture.

Hi @FALAH_FAKHRI, Once you have created a model using model=create( ) as shown in the .py file then you can do model.trainable=False. You can add new layers to model architecture. Thank you.

Many thanks for your kind reply. I did the following trail but still receiving an error as you see below, Where shall I add a layer in order to make the dimension match the following layer. any solution!

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
# Setup input shape and base model, freezing the base model layers
input_shape = (256, 256, 3)

base_model = create(classes_num=1000, image_height=299, image_width=299, image_channel=3)

base_model.trainable = False

# Create input layer
inputs = layers.Input(shape=input_shape, name="input_layer")

# Add in data augmentation Sequential model as a layer
# x = data_augmentation(inputs)

# Give base_model inputs (after augmentation) and don't train it
x = base_model(inputs, training=False)

# Pool output features of base model
x = layers.GlobalAveragePooling2D(name="global_average_pooling_layer")(x)

# Put a dense layer on as the output
outputs = layers.Dense(10, activation="softmax", name="output_layer")(x)

# Make a model with inputs and outputs
model_1 = keras.Model(inputs, outputs)

ValueError Traceback (most recent call last)

in <cell line: 18>()
17 # Give base_model inputs (after augmentation) and don’t train it
—> 18 x = base_model(inputs, training=False)
20 # # Pool output features of base model

1 frames

/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/ in _create_c_op(graph, node_def, inputs, control_inputs, op_def, extract_traceback)
1971 except errors.InvalidArgumentError as e:
1972 # Convert to ValueError for backwards compatibility.
→ 1973 raise ValueError(e.message)
1975 # Record the current Python stack trace as the creating stacktrace of this

ValueError: Exception encountered when calling layer ‘average_pooling2d_89’ (type AveragePooling2D).

Negative dimension size caused by subtracting 8 from 6 for ‘{{node Inception-v4/average_pooling2d_89/AvgPool}} = AvgPoolT=DT_FLOAT, data_format=“NHWC”, ksize=[1, 8, 8, 1], padding=“VALID”, strides=[1, 8, 8, 1]’ with input shapes: [?,6,6,1536].

Call arguments received by layer ‘average_pooling2d_89’ (type AveragePooling2D):
• inputs=tf.Tensor(shape=(None, 6, 6, 1536), dtype=float32)

Hi @FALAH_FAKHRI, When you make model.trainable= False meaning their weights will not be updated during training. But you cannot change the input_shape. As the model is created with multiple layers defined through different functions you have to make changes in the model layers present in those functions to make it work with your desired input shape. For example, decrease the number of layers, reduce the number of strides in the pooling layers, etc. Thank You.

1 Like