C3W4 low structural similarity index

Dear All,

I have tried submitting the C3W4 assignment quite a few times but despite varying hyper-parameters I can’t seem to get an average structural similarity index much above 60%. (85% is required to pass.) Am I missing something here? I think that the design choices I have made are suitable and can’t see any obvious bugs. (I have used cv2 to change channel order.)

Many thanks,

Hi @MGriff,
One possible problem is that you could be shuffling the training set.
Check this post for more details.

I have not shuffled the data, only batched it. I am using categorical cross-entropy with a softmax. Is this perhaps the error? I think that I may need to use a binary solution, perhaps with a sigmoid.

Hello @MGriff

Kindly refer the pointer mentioned in the below post to check if you any similar issue

Kindly let us know if your issue is still not resolved


The following was already done, so I am still experiencing difficulty.

Channel switching was handled through cv2.

img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

Hot encoding was performed in tf.

label_one_hot = tf.one_hot(label, num_classes)

Please send your notebook for review via DM


Hello @MGriff

Issues with your notebook

  1. in creating preprocessing function, where you def augment images(image, label),
    while you normalize the pixel values, you used true division // but you are suppose to /
    Next in the same grader cell you need to define function to take label as well using tf.one_hot, also remember instead of using num_classes use the value of num_classes

  2. Create a function to generate the saliency map
    def do_salience(image, model, label, prefix):
    img_file=image (THIS CODE IS NOT REQUIRED)

  3. in def do_salience
    Define the expected output array by one-hot encoding the label
    The length of the array is equal to the number of classes

This code is incorrect, you need to use image call function where you add an additional dimension for the batch, i.e. img_new_dim.shape[0] to the label. Also using here num_classes is correct. Also this would be called expected_output rather than label_one_hot. Please replace the same in the loss recall function for expected_output.

  1. generate the saliency maps for the 5 test images
    using label as label[0] is incorrect, you are only suppose to use 0 or 1 based on instruction Cats will have the label 0 while dogs will have the label 1 .

  2. Configure the model for training,
    incorrect loss loss=‘sparse_categorical_crossentropy’,

“categorical” will be 2D one-hot encoded labels, “binary” will be 1D binary labels, “sparse” will be 1D integer labels, so guess which loss would be correct one? Extra hint in instructions: normalize the pixel values to [0, 1]

incorrect optimizer=tf.keras.optimizers.experimental.RMSprop, kindly use tf.keras.optimizers.RMSprop

Let me know once your issue is resolved.


1 Like

Thanks, that solved the problems.

1 Like