“RMSprop”对象在加载 pickle 模型时没有属性“build”

问题描述 投票:0回答:0

尝试加载 pickle 模型时出现错误“RMSprop”对象没有属性“build”。我正在尝试加载模型以预测来自热像仪的图像。

image = tf.convert_to_tensor("C:/Users/templ/OneDrive/Desktop/fypLocal/fyp_dataset2/DPDnet_training/DPDnet_training/train/inputs/image00002")
pickled_model = pickle.load(open('model.pkl', 'rb'))
pickled_model.predict(train_generator)

错误:

Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[40], line 2
      1 image = tf.convert_to_tensor("C:/Users/templ/OneDrive/Desktop/fypLocal/fyp_dataset2/DPDnet_training/DPDnet_training/train/inputs/image00002")
----> 2 pickled_model = pickle.load(open('model.pkl', 'rb'))
      3 pickled_model.predict(train_generator)

File c:\Users\templ\OneDrive\college\FYP\FYP-1\.venv\lib\site-packages\keras\saving\pickle_utils.py:48, in deserialize_model_from_bytecode(serialized_model)
     46     model = saving_lib.load_model(filepath, safe_mode=False)
     47 except Exception as e:
---> 48     raise e
     49 else:
     50     return model

File c:\Users\templ\OneDrive\college\FYP\FYP-1\.venv\lib\site-packages\keras\saving\pickle_utils.py:46, in deserialize_model_from_bytecode(serialized_model)
     40         f.write(serialized_model)
     41     # When loading, direct import will work for most custom objects
     42     # though it will require get_config() to be implemented.
     43     # Some custom objects (e.g. an activation in a Dense layer,
     44     # serialized as a string by Dense.get_config()) will require
     45     # a custom_object_scope.
---> 46     model = saving_lib.load_model(filepath, safe_mode=False)
     47 except Exception as e:
     48     raise e
...
    975 except AttributeError as e:
    976     # Needed to avoid infinite recursion with __setattr__.
    977     if name == "_hyper":

AttributeError: 'RMSprop' object has no attribute 'build'
python machine-learning pickle
© www.soinside.com 2019 - 2024. All rights reserved.