Reinitializing Variables in Tensorflow

I use Tensorflow tf.Saverto load a pre-trained model, and I want to retrain several of my layers, erasing (reinitializing in random order) their respective weights and offsets, then training these layers and saving the trained model. I cannot find a method that reinitializes the variables. I tried tf.initialize_variables(fine_tune_vars), but it didn’t work (I would assume that the variables are already initialized), I also saw that you can pass the variables in tf.Saverso that you partially load the model, however this is half what I want to achieve (because when I save the trained model, I want it to save all the variables, not only the ones that I downloaded).

Thank you in advance!

+4
source share
1 answer

initialize_all_variables should work to reinitialize a previously initialized var.

Just did this health check at 0.10

tf.reset_default_graph()
a = tf.Variable(tf.ones_initializer(()))
init_op = tf.initialize_all_variables()
modify_op = a.assign(5.0)

sess = tf.InteractiveSession()
sess.run(init_op)
print(a.eval())
sess.run(modify_op)
print(a.eval())
sess.run(init_op)
print(a.eval())

Result

1.0
5.0
1.0
+8
source

Source: https://habr.com/ru/post/1651230/


All Articles