下面是代码的简化版本,我在第res = input - var
行出现错误
import tensorflow.contrib.slim as slim
import tensorflow as tf
x = tf.placeholder(tf.float32, shape=[None, 150, 220, 3], name='x')
input = slim.conv2d(x, num_outputs=96, kernel_size=11, stride=4, padding=padding, scope=scope, weights_initializer=tf.truncated_normal_initializer(stddev=0.01), biases_initializer=None, activation_fn=None)
var = tf.zeros_initializer()
res = input - var
变量类型
input type: <tensorflow.python.ops.init_ops.Zeros object at 0x7f1a017fdb38>
var_type: Tensor("conv1/Conv2D:0", shape=(?, 35, 53, 96), dtype=float32)
错误
TypeError: Expected float32, got <tensorflow.python.ops.init_ops.Zeros object at 0x7f1a017fdb38> of type 'Zeros' instead.
我该如何解决,任何建议都会有所帮助。
答案 0 :(得分:0)
在此行中,您尝试从张量中减去方法。
var = tf.zeros_initializer()
res = input - var