Keras负载模型:传递给优化程序的意外关键字参数:重量_衰减

nom7f22z  于 2023-03-08  发布在  其他
关注(0)|答案(1)|浏览(220)

我试图加载一个保存的模型,这是编译与Adagrad优化器。

import tensorflow as tf
from tensorflow.python import keras
from keras.optimizers import Adagrad
from Mod import MyLossPokus

modelName = "/some/path"
model = keras.models.load_model(modelName, custom_objects={'MyLossPokus': MyLossPokus, "Custom\>Adagrad": Adagrad } )

但我得到一个奇怪的错误:
TypeError: Unexpected keyword argument passed to optimizer: weight_decay. Allowed kwargs are {'global_clipnorm', 'decay', 'clipvalue', 'lr', 'clipnorm'}.
(我根本没有传递weight_decay参数!)
这是一个bug吗?还是我调用load_model函数不正确?

File "/aux/MakePredictions.py", line 105, in <module>
    LiveGames()
  File "/aux/MakePredictions.py", line 38, in LiveGames
    PredictionSmall (game)
  File "/aux/MakePredictions.py", line 56, in PredictionSmall
    model = keras.models.load_model(modelName, custom_objects={'MyLossPokus': MyLossPokus, "Custom>Adagrad": Adagrad } )
  File "/home/au/.local/lib/python3.10/site-packages/tensorflow/python/keras/saving/save.py", line 205, in load_model
    return saved_model_load.load(filepath, compile, options)
  File "/home/au/.local/lib/python3.10/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 168, in load
    model.compile(**saving_utils.compile_args_from_training_config(
  File "/home/au/.local/lib/python3.10/site-packages/tensorflow/python/keras/saving/saving_utils.py", line 207, in compile_args_from_training_config
    optimizer = optimizers.deserialize(optimizer_config)
  File "/home/au/.local/lib/python3.10/site-packages/tensorflow/python/keras/optimizers.py", line 94, in deserialize
    return deserialize_keras_object(
  File "/home/au/.local/lib/python3.10/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 674, in deserialize_keras_object
    deserialized_obj = cls.from_config(
  File "/home/au/.local/lib/python3.10/site-packages/keras/optimizers/optimizer_v2/adagrad.py", line 138, in from_config
    return cls(**config)
  File "/home/au/.local/lib/python3.10/site-packages/keras/optimizers/optimizer_v2/adagrad.py", line 84, in __init__
    super().__init__(name, **kwargs)
  File "/home/au/.local/lib/python3.10/site-packages/keras/optimizers/optimizer_v2/optimizer_v2.py", line 379, in __init__
    raise TypeError(
TypeError: Unexpected keyword argument passed to optimizer: weight_decay. Allowed kwargs are {'global_clipnorm', 'decay', 'clipvalue', 'lr', 'clipnorm'}.
cwtwac6a

cwtwac6a1#

我想对我有效的是from keras.optimizers import Adagrad,而不是根本不提供Custom\>Adagrad:)

相关问题