2

In tensorflow 1.x this can be done using a graph and a session, which is quite tedious.

Is there an easier way to manually assign pretrained weights to a specific convolution in tensorflow 2.x?

mcExchange
  • 6,154
  • 12
  • 57
  • 103

1 Answers1

1

If you are working with Keras inside Tensorflow 2.x, every layer has a method called set_weights that you can use to substitute weights or assign new ones from Numpy arrays.

Say, for example, that you are doing distillation knowledge. Then you could assign weights of the teacher to the student by:

conv.set_weights(teacher.convx.get_weights())

where conv is a particular layer of the student and convx the homologue of the teacher.

You can check the documentation for more details:

Documentation - set_weights()

BCJuan
  • 805
  • 8
  • 17