Pretty lost, I read up on averagepooling2D (link below) but it didn’t help me at all. I am thinking this is my error because everything else is explained out on what to code.
I reviewed - tf.keras.layers.AveragePooling2D | TensorFlow Core v2.7.0
I really don’t even know if that is where my error is. Something about Input is not defined?? TIA for the help
My Code:
UNQ_C3
GRADED FUNCTION: ResNet50
def ResNet50(input_shape = (64, 64, 3), classes = 6):
“”"
Stage-wise implementation of the architecture of the popular ResNet50:
CONV2D → BATCHNORM → RELU → MAXPOOL → CONVBLOCK → IDBLOCK2 → CONVBLOCK → IDBLOCK3
→ CONVBLOCK → IDBLOCK5 → CONVBLOCK → IDBLOCK2 → AVGPOOL → FLATTEN → DENSE
Arguments:
input_shape -- shape of the images of the dataset
classes -- integer, number of classes
Returns:
model -- a Model() instance in Keras
"""
# Define the input as a tensor with shape input_shape
X_input = Input(input_shape)
# Zero-Padding
X = ZeroPadding2D((3, 3))(X_input)
# Stage 1
X = Conv2D(64, (7, 7), strides = (2, 2), kernel_initializer = glorot_uniform(seed=0))(X)
X = BatchNormalization(axis = 3)(X)
X = Activation('relu')(X)
X = MaxPooling2D((3, 3), strides=(2, 2))(X)
# Stage 2
X = convolutional_block(X, f = 3, filters = [64, 64, 256], s = 1)
X = identity_block(X, 3, [64, 64, 256])
X = identity_block(X, 3, [64, 64, 256])
### START CODE HERE
## Stage 3 (≈4 lines)
X = convolutional_block(X, f = 3, filters = [128,128,512], s = 2)
X = identity_block(X, 3, [128,128,512])
X = identity_block(X, 3, [128,128,512])
X = identity_block(X, 3, [128,128,512])
## Stage 4 (≈6 lines)
X = convolutional_block(X, f = 3, filters = [256, 256, 1024], s = 2)
X = identity_block(X, 3, [256, 256, 1024])
X = identity_block(X, 3, [256, 256, 1024])
X = identity_block(X, 3, [256, 256, 1024])
X = identity_block(X, 3, [256, 256, 1024])
X = identity_block(X, 3, [256, 256, 1024])
## Stage 5 (≈3 lines)
X = convolutional_block(X, f = 3, filters = [512, 512, 2048], s = 2)
X = identity_block(X, 3, [512, 512, 2048])
X = identity_block(X, 3, [512, 512, 2048])
## AVGPOOL (≈1 line). Use "X = AveragePooling2D(...)(X)"
X = AveragePooling2D(pool_size=(2, 2))(X)
### END CODE HERE
# output layer
X = Flatten()(X)
X = Dense(classes, activation='softmax', kernel_initializer = glorot_uniform(seed=0))(X)
# Create model
model = Model(inputs = X_input, outputs = X)
return model
The error
Run the following code to build the model’s graph. If your implementation is incorrect, you’ll know it by checking your accuracy when running model.fit(…) below.
model = ResNet50(input_shape = (64, 64, 3), classes = 6)
print(model.summary())
NameError Traceback (most recent call last)
in
----> 1 model = ResNet50(input_shape = (64, 64, 3), classes = 6)
2 print(model.summary())
in ResNet50(input_shape, classes)
17
18 # Define the input as a tensor with shape input_shape
—> 19 X_input = Input(input_shape)
20
21
NameError: name ‘Input’ is not defined