Hello,
I have recently upgraded to keras 3.0 and came to know the set_value method and get_value method are gone from the keras.backend module.
Are the functions moved to a different module? or is there a different way to access variables from keras like optimizer learnig rate steps?
I am currently using optimizer.variables way but If you know what happened to set_value and get_value please do answer.
Thank you
Hi @Sohail_Mohammad, Once you have import keras 3 set the keras back end to tensorflow and can use set_value and get_value methods. For example
import os
os.environ["KERAS_BACKEND"] = "tensorflow"
import keras
print("Keras:",keras.__version__)
import tensorflow as tf
print('Tensorflow:',tf.__version__)
#output
Keras: 3.0.4
Tensorflow: 2.15.0
K = tf.keras.backend
v = K.variable(1.)
# reassign
K.set_value(v, 2.)
print(K.get_value(v))
# increment
K.set_value(v, K.get_value(v) + 1)
print(K.get_value(v))
#output
2.0
3.0
Please refer to this gist. Thank You.
it is available from:
import tensorflow.python.keras.backend as K
and also from
import keras._tf_keras.keras.backend as K
but not from keras.api.backend