Hello,
I was trying to import the optimizer module from the tensorflow package.
on the docomentation site it says:
from tensorflow.keras.optimizers import SGD
while on my pycharm, I need to import that way:
from tensorflow.python.keras.optimizers_v2 import Adam
BECAUSE I CANT FIND SGD ANYWHERE.
Also, tensorflow.python has 2 submodules named “python”.
please help.
In TF2.x, you can import optimizers as shown below
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.optimizers import Adam
Working code as shown below
import tensorflow as tf
print(tf.__version__)
from tensorflow.keras.optimizers import SGD
opt = SGD(learning_rate=0.1)
var = tf.Variable(1.0)
loss = lambda: (var ** 2)/2.0
step_count = opt.minimize(loss, [var]).numpy()
var.numpy()
Output:
2.8.2
0.9