【问题标题】:How to plot Tensor flow activation functions in a range of inputs如何在一系列输入中绘制张量流激活函数
【发布时间】:2018-11-01 15:14:05
【问题描述】:

我真的很喜欢张量流中激活函数的 2D 表示。 例如,绘图:

(tf.nn.sigmoid(

对于一系列输入,例如图像: plot

【问题讨论】:

    标签: python tensorflow plot representation


    【解决方案1】:

    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.summary.FileWriter.add_event() 只有一个参数:事件tensorflow.org/api_docs/python/tf/summary/FileWriter
    • @ArefRiant 谢谢!已编辑。当您从内存中编写代码并且不尝试时会发生这种情况:)。
    • 谢谢,我真的试图让代码正常工作,首先我遇到了错误:“不允许使用位置参数”,解决了这个问题后,我遇到了错误:TypeError:-1.0类型为 numpy.float64,但预期为以下之一:int、long
    • @ArefRiant 对此感到抱歉。编辑了代码。现在应该可以工作了。
    猜你喜欢
    • 2019-06-12
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2018-02-02
    • 1970-01-01
    相关资源
    最近更新 更多