如何在一系列输入中绘制张量流激活函数
How to plot Tensor flow activation functions in a range of inputs
我真的很喜欢张量流中激活函数的二维表示。
例如,绘制 :
(tf.nn.sigmoid(
对于一系列输入,类似于图像:
plot
Tensorboard 不是为这样的情节设计的,所以很尴尬,但你可以这样做:
import numpy as np
import tensorflow as tf
# Create '/tmp/activations' directory or point to some other directory
summary_writer = tf.summary.FileWriter(logdir='/tmp/activations')
x_numpy = np.linspace(start=-6.0, stop=6.0, num=120)
x = tf.constant(x_numpy)
y = tf.nn.sigmoid(x)
with tf.Session() as sess:
y_numpy = sess.run(y)
for x_i, y_i in zip(x_numpy, y_numpy):
# Create a tensorboard summary with sigmoid output as the value
# and sigmoid input as a step (which is normally
# the `global_step` tensor). Tensorboards plots step in x-axis.
# step must be an integer. So, we multiply x_i by 1M and convert
# it to int. This should be precise enough. In the plot,
# just ignore the "M" suffix.
value = tf.Summary.Value(tag='sigmoid', simple_value=y_i)
summary_writer.add_event(
event=tf.summary.Event(summary=tf.Summary(value=[value]),
step=int(1000000 * x_i)))
summary_writer.close()
# Point tensorboad to '/tmp/activations'
我真的很喜欢张量流中激活函数的二维表示。 例如,绘制 :
(tf.nn.sigmoid(
对于一系列输入,类似于图像: plot
Tensorboard 不是为这样的情节设计的,所以很尴尬,但你可以这样做:
import numpy as np
import tensorflow as tf
# Create '/tmp/activations' directory or point to some other directory
summary_writer = tf.summary.FileWriter(logdir='/tmp/activations')
x_numpy = np.linspace(start=-6.0, stop=6.0, num=120)
x = tf.constant(x_numpy)
y = tf.nn.sigmoid(x)
with tf.Session() as sess:
y_numpy = sess.run(y)
for x_i, y_i in zip(x_numpy, y_numpy):
# Create a tensorboard summary with sigmoid output as the value
# and sigmoid input as a step (which is normally
# the `global_step` tensor). Tensorboards plots step in x-axis.
# step must be an integer. So, we multiply x_i by 1M and convert
# it to int. This should be precise enough. In the plot,
# just ignore the "M" suffix.
value = tf.Summary.Value(tag='sigmoid', simple_value=y_i)
summary_writer.add_event(
event=tf.summary.Event(summary=tf.Summary(value=[value]),
step=int(1000000 * x_i)))
summary_writer.close()
# Point tensorboad to '/tmp/activations'