Course 4 Week 4: Assignment 1 (Face_recognition): Error in loading model locally

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')

When using the above code snippet from the exercise locally, I keep getting the following error message:

ValueError: Requested the deserialization of a Lambda layer with a Python `lambda` inside it. This carries a potential risk of arbitrary code execution and thus it is disallowed by default. If you trust the source of the saved model, you can pass `safe_mode=False` to the loading function in order to allow Lambda layer loading.

The snippet works fine in the online notebook for the course. The following are my version details

python 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:37:07) [Clang 15.0.7 ]
tensorflow 2.15.0
keras 2.15.0

Any help would be much appreciated.

Looks like you have a version compatibility issue. Sorry I’m not able to assist with that.

Yes, the versions that these courses use of TF and all the python packages is almost 3 years out of date at this point, so you can’t expect things to “just work” if you try to run them on your local computer with the latest version of everything.

There are no official solutions for this type of issue, but here’s a thread that has some links that give some directions or at least point in the general direction of how to approach the issues here.