I have a trained model, and I want to set some kernels to zero. Normally we get these kernel weights by using kernels = tf.trainable_variables() and then run the session to find the values of these weights. Although it also give us biases and fully connected layer's weights too, but i am specifically interested in convolutional kernels. So if e.g. I have 96 kernels in the first layer and I want to set Kernel# 04, 25, 26, 48, 90 set to zero, so that it can not take part in processing. how it is done? any help please.
Asked
Active
Viewed 322 times
2
-
Found the solution [here](https://stackoverflow.com/questions/47723873/modifying-the-weights-and-biases-of-a-restored-cnn-model-in-tensorflow) and also [this](https://stackoverflow.com/questions/34220532/how-to-assign-a-value-to-a-tensorflow-variable) can help a lot – Safi Sep 02 '19 at 06:34
1 Answers
1
Mentioning the Solution here for the benefit of the Community.
It can be performed via tf.assign
method. Code is mentioned below:
v1 = sess.graph.get_tensor_by_name('v1:0') #We should know the name of the Tensor
print(sess.run(v1)) # 1.0
sess.run(tf.assign(v1, 0))
print(sess.run(v1)) # 0.0