Tensorflow._api.v2.train has no attribute 'AdamOptimizer'

后端 未结 6 1495
走了就别回头了
走了就别回头了 2020-12-30 19:39

When using

model.compile(optimizer = tf.train.AdamOptimizer(),
              loss = \'sparse_categorical_crossentropy\',
              metrics=[\'accuracy\'         


        
相关标签:
6条回答
  • 2020-12-30 20:22
    tf.optimizers.Adam()
    

    Is the way to go. No reason to downgrade.
    There are lots of changes in tf 2.0 compared to 1.14.
    Note that the parameter-names of Adam have changed, too. e.g. beta1 is now beta_1, check the documentation in Meixu Songs link.

    0 讨论(0)
  • 2020-12-30 20:30
    model.compile(optimizer = tf.keras.optimizers.Adam(),
                  loss = 'sparse_categorical_crossentropy',
                  metrics=['accuracy'])
    
    0 讨论(0)
  • 2020-12-30 20:33
    tf.train.AdamOptimizer() => tf.optimizers.Adam()
    

    From https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/optimizers

    0 讨论(0)
  • 2020-12-30 20:35

    It's a minor change in upgraded version.

    Please use:

    model.compile(optimizer=tf.optimizers.Adam(), loss="sparse_categorical_crossentropy")
    

    Thanks!

    0 讨论(0)
  • 2020-12-30 20:38

    I haven't tried 2.0 yet, but from what I've seen on the dev submit videos, you can use

    model.compile(optimizer = 'adam',
               loss = 'sparse_categorical_crossentropy',
               metrics=['accuracy'])
    
    0 讨论(0)
  • 2020-12-30 20:40

    I had the same error. I removed

    tf.train.AdamOptimizer() 
    

    And I wrote

    tf.optimizers.Adam()
    

    Instead.

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