How to access kernel variables in tf.layers.conv2d?

你。 提交于 2019-12-09 13:23:06

问题


I want to visualize weights in convolutional layers to watch how they change.

But I can not find a way to access weights in convolutional layers in tf.layers.conv2d

Thank you


回答1:


You could access that variable by name:

weights = sess.run('<name_of_your_layer>/weights:0', feed_dict=...)

If you're unsure about the name of your variable, see what it could be by printing tf.trainable_variables()




回答2:


With inspiration from this: How to get CNN kernel values in Tensorflow

Make sure to give it a name:

conv_layer = tf.layers.conv2d(..., name='YOUR_NAME', ...)

Access the variables like this:

gr = tf.get_default_graph()
conv1_kernel_val = gr.get_tensor_by_name('YOUR_NAME/kernel:0').eval()
conv1_bias_val = gr.get_tensor_by_name('YOUR_NAME/bias:0').eval()


来源:https://stackoverflow.com/questions/44773643/how-to-access-kernel-variables-in-tf-layers-conv2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!