“Could not interpret optimizer identifier” error in Keras

后端 未结 14 1508
别跟我提以往
别跟我提以往 2021-02-03 19:47

I got this error when I tried to modify the learning rate parameter of SGD optimizer in Keras. Did I miss something in my codes or my Keras was not installed properly?

相关标签:
14条回答
  • 2021-02-03 20:06
    from tensorflow.keras.optimizers import SGD
    

    This works well.

    Since Tensorflow 2.0, there is a new API available directly via tensorflow:

    • https://www.pyimagesearch.com/2019/10/21/keras-vs-tf-keras-whats-the-difference-in-tensorflow-2-0/

    Solution works for tensorflow==2.2.0rc2, Keras==2.2.4 (on Win10)

    Please also note that the version above uses learning_rate as parameter and no longer lr.

    0 讨论(0)
  • 2021-02-03 20:08

    For some libraries (e.g. keras_radam) you'll need to set up an environment variable before the import:

    import os
    os.environ['TF_KERAS'] = '1'
    
    import tensorflow
    import your_library
    
    0 讨论(0)
  • 2021-02-03 20:08

    I have misplaced parenthesis and got this error,

    Initially it was

    x=Conv2D(filters[0],(3,3),use_bias=False,padding="same",kernel_regularizer=l2(reg),x))
    

    The corrected version was

    x=Conv2D(filters[0],(3,3),use_bias=False,padding="same",kernel_regularizer=l2(reg))(x)
    
    0 讨论(0)
  • 2021-02-03 20:10

    Try changing your import lines to

    from keras.models import Sequential
    from keras.layers import Dense, ...
    

    Your imports seem a little strange to me. Maybe you could elaborate more on that.

    0 讨论(0)
  • 2021-02-03 20:11

    Use one style in one kernel, try not to mix

    from keras.optimizers import sth

    with

    from tensorflow.keras.optimizers import sth

    0 讨论(0)
  • 2021-02-03 20:11

    use

    from tensorflow.keras import optimizers

    instead of

    from keras import optimizers

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