dolbi
dolbi

Reputation: 2250

Initializing new variables in tensorflow

I have built and trained a model. On second phase I want to replace the last two layers and retrain them using different data. I constantly get the errors for not initializing variables even though I did run initialization on the new vars:

var_init_op = tf.initialize_variables(var_list=[fc1_weights, fc1_biases, fc2_weights, fc2_biases]) sess.run(var_init_op)

I understand I have to initialize the new optimizer (ADAMSolever) as well, but not sure how to do that.

Assuming I want to replace the optimizer (and other variables) in the middle how do I initialize it without trashing already trained variables?

Upvotes: 1

Views: 1196

Answers (1)

csz-carrot
csz-carrot

Reputation: 275

You can get all the trainable variables using tf.trainable_variables(), and exclude the variables which should be restored from the pretrained model. Then you can initialize the other variables.

Upvotes: 3

Related Questions