python typeerror valueerror_tensorflow+Python ValueError以及解决方法

ValueError: Incompatible type conversion requested to type ‘float32’ for variable of type ‘int32_ref’

使用tensorflow时,出现在卷积层,原因在于初始化卷积权重或者偏置时, 采用整数进行初始化,导致卷积权重或者偏置为整形变量。

下面贴出我错误的代码

def bias_variable(shape, name):

with tf.name_scope('Bias'):

initial = tf.constant(0, shape=shape)

biases = tf.Variable(initial)

tf.summary.histogram(name+'/Biases_function', biases)

return biases

修改后:

def bias_variable(shape, name):

with tf.name_scope('Bias'):

initial = tf.constant(0.0, shape=shape)

biases = tf.Variable(initial)

tf.summary.histogram(name+'/Biases_function', biases)

return biases

也就是0于0.0的问题,在修改初始化参数时,一不留神就改错了,然后还不知道发生了什么。

ValueError: Incompatible shapes between op input and calculated input gradient.

我错误的原因在于使用tensorflow的反卷积tf.nn.conv2d_transpose是制定的output_shape出错了,其实函数根据输入和卷积核是可以计算输出尺寸的,也就是tf.nn.conv2d_transpose的信息是冗余的,因此,如果冗余的信息对应不上,导致误差无法反向传递。

ValueError: ‘images’ must have either 3 or 4 dimensions.

错误的代码如下:

level_map = tf.image.resize_images(gt_level, size)

说明输入的变量gt_level不是一个3-D或者4-D的tensor。查找修改即可。tf.image.resize_images的定义如下:

Signature:

tf.image.resize_images(images, size, method=0, align_corners=False)

Args:

images: 4-D Tensor of shape [batch, height, width, channels] or

3-D Tensor of shape [height, width, channels].

size: A 1-D int32 Tensor of 2 elements: new_height, new_width. The

new size for the images.

method: ResizeMethod. Defaults to ResizeMethod.BILINEAR.

align_corners: bool. If True, the centers of the 4 corner pixels of the

input and output tensors are aligned, preserving the values at the

corner pixels. Defaults to False.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值