TypeError: Unexpected keyword argument passed to optimizer: learning_rate

前端 未结 13 1620
感情败类
感情败类 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:41

    Import as mentioned below,

    import keras
    from keras.models import load_model
    from keras.models import Sequential
    
    0 讨论(0)
  • 2021-02-13 04:43

    In my case I found the best solution is to use h5py to change name of the variable from "learning_rate" -> "lr" as suggested in the previous posts.

    import h5py
    data_p = f.attrs['training_config']
    data_p = data_p.decode().replace("learning_rate","lr").encode()
    f.attrs['training_config'] = data_p
    f.close()
    
    0 讨论(0)
  • 2021-02-13 04:48

    I resolved it by reinstalling the tensorflow library (with an updated version) and also placed the nvcuda.dll file under system32 folder.

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

    I am also experiencing this when I try to load my model on another machine. Also trained the initial modal on an azure VM. I have tried the suggestions above and can't figure out what is causing it. Any other thoughts? Below is my code to train the model.

    Models were trained and are being used in my api projects using the following versions: keras 2.3.0 tensorflow 1.14.0

    history = model.fit(X, y,validation_split=0.1, \
                    epochs=20, \
                    batch_size=1000, \
                    class_weight = cw)
    
    0 讨论(0)
  • 2021-02-13 05:00

    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 05:00

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