CC3_W1_Assignment birds.h5 issue

Hi @Habibi_Ahmadi_Muslim , thanks for your help but I cannot make it work.
I’m really tired of fighting with the graders instead of learning.
This course is really frustrating to me

1 Like

I have tried again,
Loading the model from the model trained with v2.15

def load_and_compile_model():
  model2 = tf.keras.saving.load_model("birds_gpu.h5")
  model2.trainable = False
  last_layer = model2.layers[-1]
  last_layer.trainable = True
  model2.compile(optimizer=tf.keras.optimizers.SGD(momentum=0.9), 
              loss = 'mse',
              metrics = 'mse')  
  return model2 
model = load_and_compile_model()

The result seems OK:

Layer (type) Output Shape Param # Trainable

input_3 (InputLayer) [(None, 224, 224, 3)] 0 N

mobilenetv2_1.00_224 (Func (None, 7, 7, 1280) 2257984 N
tional)

global_average_pooling2d_1 (None, 1280) 0 N
(GlobalAveragePooling2D)

flatten_1 (Flatten) (None, 1280) 0 N

dense_2 (Dense) (None, 1024) 1311744 N

dense_3 (Dense) (None, 512) 524800 N

bounding_box (Dense) (None, 4) 2052 Y


But the same error while submitting the file birds.h5 to coursera:
Your model could not be loaded. Make sure it is a valid h5 file.

:scream:
@Jorge_Murria, sorry for the delay and thanks for bringing this up! Some variation of @Habibi_Ahmadi_Muslim’s work-around should work, but definitely we shouldn’t be making students jump through those hoops. If Colab is no longer supporting GPU for TF 2.8, then we need to either fix the assignment to do any version-related gymnastics for you, or fix the grader to work with a more current version of TF. I’ll report to staff right away so they can figure out how to fix this.

1 Like

For anyone who runs into this problem:

Since staff is on break until January 2nd, and this also might take a little while to fix, I think this hacky work-around should be enough to make the autograder happy:

  1. First, in order to use the GPU in Colab, do NOT run this cell near the beginning of the assignment:
# Install packages for compatibility with the autograder
!pip install tensorflow==2.8.0
!pip install keras==2.8.0
  1. At the beginning of section 5.2 Save your model for grading, add these cells:
    a)
# First save the model we made using tf 2.15
model.save("birds_gpu.h5")

b)

# Install version of tf used by grader
!pip install tensorflow==2.8.0
!pip install keras==2.8.0

import tensorflow as tf
import tensorflow_datasets as tfds

When you run this cell, it will probably show you a Restart button that you need to press to start usinig the 2.8.0 version of Tensorflow. After pressing Restart, you can re-run this cell to confirm everything is now loaded properly
c)

model = tf.keras.models.load_model("birds_gpu.h5", compile=False)

After this, you can run the existing cell to save the model as “birds.h5”, and download the birds.h5 file to your computer. This should be enough to make the grader happy.

Note: When you download birds.h5 to your computer, make sure you have deleted or renamed any previous copies of birds.h5

4 Likes

Hi @Wendy , thanks a lot for your help. It worked!!

1 Like

Hi everyone! If you encounter this issue again in other assignments, you can use the fallback runtime so you can use the GPU with older TF versions. Instructions here. Nonetheless, we’ve taken note of this so the grader can be upgraded before the fallback runtime becomes unavailable. Thanks!

1 Like

@Habibi_Ahmadi_Muslim Could you please provide me your W2 model.h5 file on the given email? I’m having trouble with specific configurations that prevent my model from training, and the loss never goes down.

hafiz666152001@gmail.com