How to restore weights with different names but same shapes Tensorflow?

Viewed 3844

I have multiple architectures in Tensorflow. Some of them share the design of certain parts.

I would like to train one of the networks and use the trained weights of the similar layers in another network.

At this point in time, I am able to save the weights I want and reload them in an architecture with an exactly similar naming convention for the variables.

However, when the weights have different names in the two networks, it is not possible to restore. I have this naming convention for the first network:

  • selector_network/c2w/var1

in the second network I have this:

  • joint_network/c2w/var1

Apart from that, the variables are similar in terms of shape. Is there a possibility to change the names upon reloading or to tell Tensorflow where to fit those variables?

EDIT: I found this script from @batzner that allows renaming the variables of a Tensorflow checkpoint : tensorflow_rename_variables.

It is not working. I get the following error:

ValueError: Couldn't find 'checkpoint' file or checkpoints in given directory ./joint_pos_tagger_lemmatizer/fi/
2 Answers

Still,there is a way if you don't save it. Write a map function so you can use it to choose the right tensor.And use tensor.assign() to assign the value from the first network.

Related