Henry
Henry

Reputation: 113

Tensorflow 1.14 equivalent of Tensorflow 2.0 model.trainable_variables

How can I replace Tensorflow 2.0 model.trainable_variables in Tensorflow.1.14 (https://www.tensorflow.org/beta/guide/effective_tf2) ?

Upvotes: 0

Views: 346

Answers (1)

gorjan
gorjan

Reputation: 5555

Assuming that you have two tf.keras.Model:

model_1 = tf.keras.Sequential([tf.keras.layers.Dense(100, name="model_1/dense1")])
model_1.build(input_shape=(None, 50))
model_2 = tf.keras.Sequential([tf.keras.layers.Dense(100, name="model_2/dense1")])
model_2.build(input_shape=(None, 50))

You can obtain the trainable variables of the first model like this:

model_1_trainable = [variable for variable in tf.trainable_variables() if variable.name.startswith("model_1")]

Upvotes: 1

Related Questions