Running Course 4 Week 4 Face Recognition Programming Assignment notebook offline

Hello @David00,

Though my python environment might be different from yours, I had the same error message loading the assignment’s model. My way out was to (1) load the model on Coursera, (2) save it in another format (a folder that contains a couple of files), (3) zip it, (4) download it, (5) unzip it, and finally (6) load it in my environment. (Code at the end)

Step 6 can run successfully, but I am not sure if there is any issue with the loaded model, so you will need to check it yourself.

Lastly, we do not really provide support for learners working on a lab in other environments. Moreover, the lab was also only tested to work on Coursera, so it is possible that some tests that were passed on Coursera failed in your environment. There is no guarantee on the reproducibility of results across different environments.

Raymond

Step 1 - 3 (on coursera)

from tensorflow.keras.models import model_from_json

json_file = open('keras-facenet-h5/model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
model.load_weights('keras-facenet-h5/model.h5')

## Added code below. To be removed after use, or it may interfere with the grader at submission
import shutil
model.save("my_model") # save model in another format
shutil.make_archive('my_model', 'zip', 'my_model') # zip the saved model

Step 6 (in your environment)

### commented out the original code for loading the model
# from tensorflow.keras.models import model_from_json

# json_file = open('keras-facenet-h5/model.json', 'r')
# loaded_model_json = json_file.read()
# json_file.close()
# model = model_from_json(loaded_model_json)
# model.load_weights('keras-facenet-h5/model.h5')

# Added code below, for loading the model saved in a different format
model = tf.keras.models.load_model("my_model") # make sure to finish step 5 first, and then put down the path to the model.
3 Likes