How do I use tensor board with tf.layers?

让人想犯罪 __ 提交于 2019-12-10 15:39:23

问题


As the weights are not explicitly defined, how can I pass them to a summary writer?

For exemple:

conv1 = tf.layers.conv2d(
    tf.reshape(X,[FLAGS.batch,3,160,320]),
    filters = 16,
    kernel_size = (8,8),
    strides=(4, 4),
    padding='same',
    kernel_initializer=tf.contrib.layers.xavier_initializer(),
    bias_initializer=tf.zeros_initializer(),
    kernel_regularizer=None,
    name = 'conv1',
    activation = tf.nn.elu
    )

=>

summarize_tensor(
    ??????
)

Thanks!


回答1:


That depends on what you are going to record in TensorBoard. If you want to put every variables into TensorBoard, call tf.all_variables() or tf.trainable_variables() will give you all the variables. Note that the tf.layers.conv2d is just a wrapper of creating a Conv2D instance and call apply method of it. You can unwrap it like this:

conv1_layer = tf.layers.Conv2D(
    filters = 16,
    kernel_size = (8,8),
    strides=(4, 4),
    padding='same',
    kernel_initializer=tf.contrib.layers.xavier_initializer(),
    bias_initializer=tf.zeros_initializer(),
    kernel_regularizer=None,
    name = 'conv1',
    activation = tf.nn.elu
)

conv1 = conv1_layer.apply(tf.reshape(X,[FLAGS.batch,3,160,320]))

Then you can use conv1_layer.kernel to access the kernel weights.




回答2:


While Da Tong's answer is complete, it took me a while to realize how to use it. To save time for another beginner, you need to add the following to you code to add all trainable variables to the tensorboard summary:

for var in tf.trainable_variables():
    tf.summary.histogram(var.name, var)
merged_summary = tf.summary.merge_all()


来源:https://stackoverflow.com/questions/44731808/how-do-i-use-tensor-board-with-tf-layers

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