Home > OS >  Understand relation between different tensorflow AdagradOptimizer APIs
Understand relation between different tensorflow AdagradOptimizer APIs

Time:10-13

I am new to tf, and during reading a model code, I noticed it used 1), but most document I can find are using 2) and 3). So what is the tensorflow.python library used for,seems it is not in official document? And what is the relation between 1 to 2,3?

  1. from tensorflow.python.training.adagrad import AdagradOptimizer
  2. from tf.compat.v1.train import AdagradOptimizer
  3. from tf.keras.optimizers import Adagrad

CodePudding user response:

Basically:

  1. tensorflow.python is essentially "internal" code and not part of the public API. You should never use anything in there directly. It may work, but it can also lead to instabilities, break completely if you update your TF version, etc.
  2. This is a hold-over from old TF versions, before Keras was tightly integrated with it. IMHO you should just forget that this exists and they should have just removed it completely. This would be used with the outdated layers interface (tf.compat.v1.layers).
  3. This is what you should use if using tf.keras (models and/or layers) and should be your go-to interface (not necessarily Adagrad specifically, but all the optimizers in tf.keras.optimizers).
  • Related