python - 加载 tensorflow 模型时出错 - TypeError: __init__() got an unexpected keyword argument 'axis'
问题描述
我训练了我的模型并将其保存为 .h5 文件,当我尝试通过 load_model() 再次加载模型时,我收到了这个错误,这是我得到的全部代码和错误。
我正在使用张量流 2.3.0
from tensorflow import keras
age_model_path = r"C:\Users\dipesh\Desktop\Age-Gender Detection\models\Age_Prediction_model.h5"
gender_model_path = r"C:\Users\dipesh\Desktop\Age-Gender Detection\models\Gender_Prediction_model.h5"
age_model = keras.models.load_model(age_model_path)
gender_model = keras.models.load_model(gender_model_path)
我得到的错误:
23:06:34.517588: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX AVX2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. Traceback (most recent call last): File "C:/Users/dipesh/PycharmProjects/Age_Gender_Detection/API.py", line 100, in <module>
prediction = get_gender_age(img_path,gender_model_path,age_model_path) File "C:/Users/dipesh/PycharmProjects/Age_Gender_Detection/API.py", line 76, in get_gender_age
gender_model = keras.models.load_model(gender_model_path) File "C:\Users\dipesh\anaconda3\lib\site-packages\tensorflow\python\keras\saving\save.py", line 182, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile) File "C:\Users\dipesh\anaconda3\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py", line 193, in load_model_from_hdf5
model.compile(**saving_utils.compile_args_from_training_config( File "C:\Users\dipesh\anaconda3\lib\site-packages\tensorflow\python\keras\saving\saving_utils.py", line 217, in compile_args_from_training_config
loss = _deserialize_nested_config(losses.deserialize, loss_config) File "C:\Users\dipesh\anaconda3\lib\site-packages\tensorflow\python\keras\saving\saving_utils.py", line 258, in _deserialize_nested_config
return deserialize_fn(config) File "C:\Users\dipesh\anaconda3\lib\site-packages\tensorflow\python\keras\losses.py", line 1850, in deserialize
return deserialize_keras_object( File "C:\Users\dipesh\anaconda3\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py", line 360, in deserialize_keras_object
return cls.from_config(cls_config) File "C:\Users\dipesh\anaconda3\lib\site-packages\tensorflow\python\keras\losses.py", line 163, in from_config
return cls(**config) TypeError: __init__() got an unexpected keyword argument 'axis'