I wanna draw the weights of tf.layers.dense in tensorboard histogram, but it not show in the parameter, how could I do that?
For obtaining the weights, just use obj. trainable_weights this returns a list of all the trainable variables found in that layer's scope.
dense() is an inbuilt function of Tensorflow. js library. This function is used to create fully connected layers, in which every output depends on every input. Syntax: tf.layers.dense(args)
The weights are added as a variable named kernel
, so you could use
x = tf.dense(...)
weights = tf.get_default_graph().get_tensor_by_name(
os.path.split(x.name)[0] + '/kernel:0')
You can obviously replace tf.get_default_graph()
by any other graph you are working in.
I came across this problem and just solved it. tf.layers.dense
's name is not necessary to be the same with the kernel's name's prefix. My tensor is "dense_2/xxx" but it's kernel is "dense_1/kernel:0". To ensure that tf.get_variable
works, you'd better set the name=xxx
in the tf.layers.dense
function to make two names owning same prefix. It works as the demo below:
l=tf.layers.dense(input_tf_xxx,300,name='ip1')
with tf.variable_scope('ip1', reuse=True):
w = tf.get_variable('kernel')
By the way, my tf version is 1.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With