tensorflow Bug汇集以及解决

tensorflow Bug汇集以及解决


主要收集我自己在写代码以及Debug过程中遇到的不那么容易解决的bug.

1.

Could not set cudnn filter descriptor:CUDNN_STATUS_BAD_PARAM

遇到这个问题,一般是由于在做BP的时候,有一个梯度tensor的batch_size为0导致。
例如,我在实现FPN的时候有这么一段代码:

with tf.variable_scope('crop_roi_and_roi_align'):
    for i in range(2, 6):
        level_i_proposal_indices = tf.reshape(tf.where(tf.equal(levels, i)), [-1])
        level_i_proposals = tf.gather(self.first_stage_decode_boxes, level_i_proposal_indices)

        all_level_proposal_list.append(level_i_proposals)

        ymin, xmin, ymax, xmax = tf.unstack(level_i_proposals, axis=1)
        img_h, img_w = tf.cast(self.img_shape[1], tf.float32), tf.cast(self.img_shape[2], tf.float32)
        normalize_ymin = ymin / img_h
        normalize_xmin = xmin / img_w
        normalize_ymax = ymax / img_h
        normalize_xmax = xmax / img_w

        level_i_cropped_rois = tf.image.crop_and_resize(
            self.feature_pyramid['P%d' % i],
            boxes=tf.transpose(tf.stack([normalize_ymin,
            normalize_xmin,normalize_ymax, normalize_xmax])),
            box_ind=tf.zeros(shape=[tf.shape(level_i_proposals)[0],],dtype=tf.int32),
            crop_size=[self.initial_crop_size, self.initial_crop_size])
        level_i_rois = slim.max_pool2d(level_i_cropped_rois,
                                       [self.max_pool_kernel_size, self.max_pool_kernel_size],
                                       stride=self.max_pool_kernel_size)
        all_level_roi_list.append(level_i_rois)

其中有个很重要的地方就是这个tf.image.crop_and_resize这个函数,有个指示batchid的参数。我是这样指定的:
box_ind=tf.zeros(shape=[tf.shape(level_i_proposals)[0],],dtype=tf.int32)。而level_i_proposals很有可能是[],也就是说它的shape是0, 这样就会导致box_ind为[],也就是说batch_size为0.所以会报错。
解决:
在产生level_i_proposals的时候加一个条件,使得all_level_proposal的shape不为0.

with tf.variable_scope('crop_roi_and_roi_align'):
    for i in range(2, 6):
        level_i_proposal_indices = tf.reshape(tf.where(tf.equal(levels, i)), [-1])
        level_i_proposals = tf.gather(self.first_stage_decode_boxes, level_i_proposal_indices)

        level_i_proposals = tf.cond(
            tf.equal(tf.shape(level_i_proposals)[0], 0),
            lambda: tf.constant([[0, 0, 0, 0]], dtype=tf.float32),
            lambda: level_i_proposals
        )  # to avoid level_i_proposals batch is 0, or it will broken when gradient BP

问题解决。


2.

Ran out of GPU memory when allocating 0 bytes for[[Node]: softmax_cross_entropy_loss/xentropy

出现这样的情况不是因为显存不够导致,是因为在做cross_entropy_loss的时候,logits或者label是这样的:[].也就是空的。(当然大部分是因为偶然出现一次这样的Bug而导致程序中断)。
解决:

保证程序的鲁棒性,确保不会出现logits或者label[]的情况。

待续。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值