C4 W2 residual networks, Inputs have incompatible shapes

please help, I’ve been stuck here for hours. This is from the convolutional block, I literally just copy pasted this (the part that is already done):

X = Conv2D(filters = F1, kernel_size = 1, strides = (s, s), padding=‘valid’, kernel_initializer = initializer(seed=0))(X)
X = BatchNormalization(axis = 3)(X, training=training)
X = Activation(‘relu’)(X)

and changed the parameters filters, kernel_size, strides, etc. as requested (also deleted the ReLU part when needed), but still nothing ):

Try putting “training=training” inside the layer definition, not in the data argument (doesn’t belong with “X”).

I don’t think so ): in the identity_block it works with (X, training=training). Also, that’s how it is written in the notebook.

I tried anyway, but this new error appeared: TypeError: (‘Keyword argument not understood:’, ‘training’)

My mistake, you are correct about the training = training placement.

Is there more to the error message? Please post an image of the entire message.

Maybe you are making a mistake in X_shortcut. Note that input, in this case, is X_shortcut, not X.


ValueError Traceback (most recent call last)
Input In [5], in <cell line: 3>()
1 ### you cannot edit this cell
----> 3 public_tests.convolutional_block_test(convolutional_block)

File /tf/W2A1/public_tests.py:102, in convolutional_block_test(target)
98 X3 = np.ones((1, 4, 4, 3)) * 3
100 X = np.concatenate((X1, X2, X3), axis = 0).astype(np.float32)
→ 102 A = target(X, f = 2, filters = [2, 4, 6], training=False)
104 assert type(A) == EagerTensor, “Use only tensorflow and keras functions”
105 assert tuple(tf.shape(A).numpy()) == (3, 2, 2, 6), “Wrong shape.”

Input In [4], in convolutional_block(X, f, filters, s, training, initializer)
49 X = BatchNormalization(axis = 3)(X, training=training)
53 # Final step: Add shortcut value to main path (Use this order [X, X_shortcut]), and pass it through a RELU activation
—> 54 X = Add()([X, X_shortcut])
55 X = Activation(‘relu’)(X)
57 return X

File /usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py:67, in filter_traceback..error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.traceback)
—> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb

File /usr/local/lib/python3.8/dist-packages/keras/layers/merging/base_merge.py:73, in _Merge._compute_elemwise_op_output_shape(self, shape1, shape2)
71 else:
72 if i != j:
—> 73 raise ValueError(
74 ‘Inputs have incompatible shapes. ’
75 f’Received shapes {shape1} and {shape2}’)
76 output_shape.append(i)
77 return tuple(output_shape)

ValueError: Inputs have incompatible shapes. Received shapes (1, 1, 6) and (4, 4, 3)

here’s the whole message

thanks a lot, that solved the problem. I wasn’t paying close attention to the diagram above

Glad to hear that you figured it out. I was just about to comment that Saif’s suggestion was precisely “on the money” in that the exception trace pointed exactly to the line where you added the shortcut value. :nerd_face:

1 Like