Using .h5 model from Keras 2.6 #20617
Unanswered
demybug123
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been working with the models from this repository: https://github.com/daniegr/EfficientPose/tree/master
It provides model and scripts for 3 framework but I mostly only use Keras.
Python and module versions that I use:
Python 3.7
Tensorflow 2.6
Keras 2.6
With the environment setup above, I can load the model from master/models/keras and run model.predict. It works, just with a couple of warning of deprecation. The problem is that I want to migrate it to Python 3.12 and keras 3.7 (for better performance and compatibility with my other scripts). I've looked online for guide to migration but the original project only provided .h5 files, no training or model declaration code and the repo has been inactive for a while.
I'm asking if it is possible to load models from old .h5 files and where should I start? So far I've tried installing newer environment and updating import for
EfficientPose/tree/master/utils/helpers.py
.I tried:
from utils import helpers
from keras._tf_keras.keras.models import load_model
model = load_model(f'path\models\\keras\\EfficientPoseI.h5', custom_objects={'BilinearWeights': helpers.keras_BilinearWeights, 'Swish': helpers.Swish(helpers.eswish), 'eswish': helpers.eswish, 'swish1': helpers.swish1})
Got error:
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\saving\saving_api.py", line 196, in load_model
return legacy_h5_format.load_model_from_hdf5(
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\legacy\saving\legacy_h5_format.py", line 133, in load_model_from_hdf5
model = saving_utils.model_from_config(
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\legacy\saving\saving_utils.py", line 85, in model_from_config
return serialization.deserialize_keras_object(
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\legacy\saving\serialization.py", line 495, in deserialize_keras_object
deserialized_obj = cls.from_config(
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\models\model.py", line 527, in from_config return functional_from_config(
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\models\functional.py", line 546, in functional_from_config
process_layer(layer_data)
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\models\functional.py", line 514, in process_layer
layer = saving_utils.model_from_config( File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\legacy\saving\saving_utils.py", line 85, in model_from_config
return serialization.deserialize_keras_object(
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\legacy\saving\serialization.py", line 490, in deserialize_keras_object
cls_config = _find_replace_nested_dict(
File "D:\python\Fall Detection Project\EfficientPose312\.venv\Lib\site-packages\keras\src\legacy\saving\serialization.py", line 571, in _find_replace_nested_dict
dict_str = json.dumps(config)
File "C:\Users\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 231, in dumps return _default_encoder.encode(obj)
File "C:\Users\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py", line 200, in encode chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py", line 258, in iterencode return _iterencode(o, 0)
File "C:\Users\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py", line 180, in default raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type function is not JSON serializable
Beta Was this translation helpful? Give feedback.
All reactions