【问题标题】:ValueError: setting an array element with a sequence with TensorflowValueError:使用 Tensorflow 设置具有序列的数组元素
【发布时间】:2023-03-16 07:32:01
【问题描述】:

我正在尝试重现 deep video portrait (2018),他们指的是实现 patchGAN 的 Isola (2017)。

在 patchGAN 中,判别器返回张量的 [batch_size, patch_width, patch_height, 1],我想将此张量提供给我的损失,定义如下:

EcGAN = tf.reduce_mean(tf.log(D_real)+ tf.log(np.float32(1. - D_fake))) 

所以我包含了以下伪操作检查器并运行:

sheudo_input = tf.Variable(np.float32(np.random.uniform(low=-1., high=1., size=[16, 30, 30, 1]))) 
EcGAN = tf.reduce_mean(tf.log(sheudo_input)+ tf.log(np.float32(1. - sheudo_input))) 

但EcGAN 未计算并返回如下错误:

ValueError: setting an array element with a sequence.

可能的问题是什么以及如何解决?

【问题讨论】:

    标签: python arrays numpy tensorflow sequence


    【解决方案1】:

    np.float32 电话是问题所在。除非在急切执行模式下,否则 Numpy 函数不能很好地处理张量。

    尝试投射时,您应该使用tf.cast。或者在这种情况下,结果应该是一个浮点数无论如何,所以这就足够了:

    tf.log(sheudo_input) + tf.log(1. - sheudo_input)
    

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 2018-02-07
      • 1970-01-01
      • 2018-04-25
      相关资源
      最近更新 更多