Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi everyone,
I'm new to Keras and TensorFlow and currently exploring them for a personal project focused on emotion detection from images.
I'm using:

  • Keras version: 3.9.2

  • TensorFlow version: 2.19.0

I'm trying to load a pre-trained model from a JSON file using the following code:

from tensorflow.keras.models import load_model, model_from_json
import os
MODEL_FOLDER_PATH = r"C:\Users\User\Project\Emotion_Analyzer\model"

JSON_FILE_NAME = "emotion_model.json"
H5_WEIGHTS_FILE_NAME = "emotion_model.h5" 

JSON_PATH = os.path.join(MODEL_FOLDER_PATH, JSON_FILE_NAME)
WEIGHTS_PATH = os.path.join(MODEL_FOLDER_PATH, H5_WEIGHTS_FILE_NAME)

with open(JSON_PATH, 'r') as json_file:
    loaded_model_json = json_file.read()
model = model_from_json(loaded_model_json)
model.load_weights(WEIGHTS_PATH)
model.summary()

However, I'm encountering the following error:

---> 12 model = model_from_json(loaded_model_json) 
TypeError: Could not locate class 'Sequential'. Make sure custom classes are decorated with `@keras.saving.register_keras_serializable()`. Full object config: 

After some research, I found that this issue likely stems from compatibility problems between the model's original version (Keras 2.4.0) and the version I'm currently using (3.9.2).
Could someone please guide me on how to resolve this error without downgrading to an older Keras version?
emotion_model.json

Any help would be greatly appreciated!

Thanks!

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.