TypeError: Unexpected keyword argument passed to optimizer: learning_rate

前端 未结 13 1649
故里飘歌
故里飘歌 2021-02-13 04:14

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:44

    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)
  • 2021-02-13 04:46

    That issue usual on dependencies difference between the kernel where that model has been trained and the dependencies versions where the model is being loaded.

    If you have installed the latest version of Tensorflow now (2.1) try to load the model like this:

    import tensorflow as tf
    print(tf.__version__)
    print("Num GPUs Available: ", 
           len(tf.config.experimental.list_physical_devices('GPU')))
    # Checking the version for incompatibilities and GPU list devices 
    # for a fast check on GPU drivers installation. 
    
    model_filepath = './your_model_path.h5'
    
    model = tf.keras.models.load_model(
        model_filepath,
        custom_objects=None,
        compile=False
    )
    

    Compile=False only if the model has already compiled.

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

    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:55

    It was a simple fix for me. Check your tensorflow version. I trained my model on 1.14 and was predicting it on 2.0

    I used 1.14 again and it worked

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

    i got the same error while i was working in two different PC. in some versions of tensorflow is tf.keras.optimizers.SGD(lr = x) while in other verions istf.keras.optimizers.SGD(learning rate = x).

    0 讨论(0)
  • 2021-02-13 05:00

    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)
提交回复
热议问题