首页 文章

在Tensorflow中提供隐藏的张量

提问于
浏览
0

我有一些 autoencoder . 该模型现在并不重要 . 假设该模型将一些图像作为输入并输出重建图像 . 训练结束后,我希望看到一个张量对输出的影响 . 此外,图像通过 FIFOQueue 输入 autoencoder . 因此,在运行以下代码时:

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

其中 deconv_image 是模型的输出 tensormu 是模型内部的隐藏张量;将使用 Queue 中的图像自动为模型提供信息 .

我的问题是: mu 中的值是否会被来自输入图像的任何内容所取代,或者,它采用我使用 feed_dict 参数提供的向量 .

任何帮助深表感谢!!

1 回答

  • 0

    当运行最终张量时,即评估图的最后张量时,它将运行它所依赖的所有张量 . 因此,如果我们有依赖于 y2y3 操作和 y2 取决于 y1 ,则在图中运行最终张量将导致 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.]
    

相关问题