How do I access kernel variables in tf.layers.conv2d?

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

But I can't find a way to access the weights in the convolutional layers in tf.layers.conv2d

thank

+3


source to share


2 answers


You can access this variable by name:

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

      



If you are unsure of the name of your variable, see what it might be by typing tf.trainable_variables()

+3


source


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

Be sure to give him a name:

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

      



Access to such variables:

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()

      

+1


source







All Articles