Method of loading partial layers based on tensorflow

  • 2020-11-18 06:19:54
  • OfStack

1, use


saver.restore(sess, modeldir + "model.ckpt")

The trained network can be loaded, but sometimes you want to use the parameters of part of the layer. In this case, you can choose to reinitialize the remaining layer after the network is loaded


var_list = [weights['wd1'], weights['out'], biases['bd1'], biases['out'], global_step]
initfc = tf.variables_initializer(var_list, name='init')

For example, if we want to reinitialize the layers in var_list, we can do so again after restore


sess.run(init)
saver.restore(sess, modeldir + "model.ckpt")
print sess.run(global_step)
#initialize several layer
sess.run(initfc)
print sess.run(global_step)

You can see that some of the variables have been reinitialized


Related articles: