【问题标题】:Feeding a hidden tensor in Tensorflow在 Tensorflow 中输入一个隐藏的张量
【发布时间】:2017-07-27 22:24:57
【问题描述】:

我有一个 autoencoder。模型现在并不重要。假设该模型将一些图像作为输入并输出重建图像。训练后,我想看看一个张量对输出的影响。此外,图像正在通过FIFOQueue 输入autoencoder。因此,运行时和平代码如下:

reconstructed_image = sess.run([deconv_image], feed_dict={mu:my_vector})

其中deconv_image是模型的输出tensormu是模型内部的隐藏张量;将自动为模型提供来自Queue 的图像。

我的问题是:mu 中的值是否会被来自输入图像的任何值替换,或者,它采用我使用 feed_dict 参数提供的向量。

非常感谢任何帮助!

【问题讨论】:

    标签: tensorflow autoencoder


    【解决方案1】:

    在运行最终张量时,即评估图的最后一个张量,它将运行它所依赖的所有张量。因此,如果我们有依赖于y2y2 依赖于y1y3 操作,那么,在图中运行最终张量将导致y1 首先运行,然后y2 在之后评估它从y1 获取输入,最后y2 的输出将输入y3。该图可能如下:y1 -> y2 -> y3

    另一方面,我可以通过使用feed_dict 参数直接输入其输入来运行(评估)y3。在这种情况下,会评估 y2y1

    例如:

    import tensorflow as tf
    import numpy as np
    
    x = np.array([1.0, 2.0, 3.0])
    
    x_var = tf.Variable(x, dtype=tf.float32)
    
    y1 = tf.square(x_var)
    y2 = tf.subtract(y1, tf.constant(1.0))
    
    init_op = tf.global_variables_initializer()
    
    with tf.Session() as sess:
        sess.run(init_op)
    
        print(sess.run(y2)) # Output: [ 0.  3.  8.]
        print(sess.run(y2, feed_dict={y1: [1.0, 1.0, 1.0]}))# Output: [ 0.  0.  0.]
    

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 2020-05-01
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      相关资源
      最近更新 更多