I hear your frustration, and I want to be clear that the purpose of this community is absolutely to help you apply what you learn to practical problems. Your questions are welcome here.
You’ve brought up a really important point that gets to the heart of a common challenge in software: the difference between reproducibility and updating.
I think there may be a slight misunderstanding of terms here. The course content is 100% reproducible in the environment it was designed for, with the original library versions. We ensure that so the learning experience is stable.
What you’re trying to do, which is a great learning exercise, is to update the old code to run with the very latest libraries. As you know, that’s a much more complex task. Libraries evolve, syntax changes, functions are moved, and even subtle things like how random numbers are generated can differ between versions. It’s a significant engineering challenge, not just a simple rerun of the code.
So I’m just being transparent with you, as much as I’d like to help you with a quick solution. The challenge you’re facing is a classic migration issue that developers often encounter.
Here’s a quick reply from an LLM on how you can approach the issue you are facing:
1. The Root of the TypeError
The error TypeError: Could not locate class 'Functional' is a strong clue. The way Keras saves and loads model architecture has changed significantly since TensorFlow 2.3. The older model_from_json method is now deprecated and often fails with newer versions because the internal structure of the model object (like the Functional class) isn’t recognized from the old JSON format.
2. The Modern Approach: Unified Model Files
Instead of a separate .json for the architecture and .h5 for the weights, the modern standard is to use a single, unified format. The recommended way to save and load a complete model is:
- To save:
model.save('my_model.keras')
- To load:
model = tf.keras.models.load_model('my_model.keras')
This single file contains everything: the architecture, weights, and optimizer state.
3. A Practical First Step
Since you don’t have the original code that created the model, you can’t re-save it in the new .keras format. However, you can try loading the weights into a newly defined model structure. If you can find the Python code that defines the FaceNet model’s architecture in the assignment, you could:
- Re-create the model architecture in your code.
- Load only the weights onto this new model using
new_model.load_weights('keras-facenet-h5/model.h5').
This approach bypasses the problematic .json file entirely and is much more likely to work in TF 2.20. It directly answers your question: you don’t need a new .json file if you rebuild the model in code and load the weights.
I hope these pointers are helpful and give you a good direction to explore!
Best,
Mubsi