TypeError: Unexpected keyword argument passed to optimizer: learning_rate

前端 未结 13 1606
感情败类
感情败类 2021-02-13 04:16

I am trying to load a Keras model which was trained on an Azure VM (NC promo). But I am getting the following error.

TypeError: Unexpected keyword argumen

相关标签:
13条回答
  • 2021-02-13 04:35

    This happened to me too. Most likely because the learning_rate was renamed from version 2.2.* to 2.3.0 in September 2018. (see release notes: https://github.com/keras-team/keras/releases : Rename lr to learning_rate for all optimizers. )

    This worked for me:

    sudo pip install keras --upgrade 
    
    0 讨论(0)
  • 2021-02-13 04:35

    Did you use a custom optimizer?

    If so, you can load like this:

    model = load_model('my_model_name.h5', custom_objects={
        'Adam': lambda **kwargs: hvd.DistributedOptimizer(keras.optimizers.Adam(**kwargs))
    })
    

    Alternatively you can load your model with model = load_model('my_model_name.h5', compile=False) and then add an optimizer and recompile, but that will lose your saved weights.

    0 讨论(0)
  • 2021-02-13 04:37

    Similar to Chayan Bansal, what fixed it for me was to update my Tensorflow-GPU library.

    If you're using Anaconda with tensorflow-gpu installed, open the Anaconda prompt, activate the virtual environment you're using, and enter "conda update tensorflow-gpu"

    0 讨论(0)
  • 2021-02-13 04:38

    I was running into the same thing. You will have to upgrade to Tensorlfow 2.0 and Keras, or match the two systems together.

    0 讨论(0)
  • 2021-02-13 04:40

    I had the same problem. Using Keras version 2.3.1 and TensorFlow-GPU version 1.13, I had to upgrade Tensorflow-GPU to version 1.15

    pip uninstall tensorflow-gpu
    pip install tensorflow-gpu==1.15
    
    0 讨论(0)
  • 2021-02-13 04:41

    I've had a similar problem.

    You you have this issue, try to use lr instead of learning_rate when defining the learning rate in your optimizer.

    0 讨论(0)
提交回复
热议问题