Stinky-Tofu / Stronger-yolo

🔥Improve yolo with latest paper
MIT License
3 stars 0 forks source link

关于样本图片标注框转换成预测数据的问题 #77

Open 123lifei opened 5 years ago

123lifei commented 5 years ago

exist_positive = False for i in range(3): anchors_xywh = np.zeros((self.anchor_per_scale, 4)) anchors_xywh[:, 0:2] = np.floor(bbox_xywh_scaled[i, 0:2]).astype(np.int32) + 0.5 anchors_xywh[:, 2:4] = self.anchors[i]

            iou_scale = utils.iou_calc2(bbox_xywh_scaled[i][np.newaxis, :], anchors_xywh)
            iou.append(iou_scale)
            iou_mask = iou_scale > 0.3

            if np.any(iou_mask):
                xind, yind = np.floor(bbox_xywh_scaled[i, 0:2]).astype(np.int32)

                # (4)将iou大于0.3的anchor对应位置的数据标识为(x, y, w, h, 1, classes)
                # 首先需要将该Anchor对应的标签清零,因为某个Anchor可能与多个bbox的IOU大于0.3
                # 如果不清零,那么该Anchor可能会被标记为多类
                label[i][yind, xind, iou_mask, :] = 0
                label[i][yind, xind, iou_mask, 0:4] = bbox_xywh
                label[i][yind, xind, iou_mask, 4:5] = 1.0
                label[i][yind, xind, iou_mask, 5:] = smooth_onehot

                bbox_ind = int(bbox_count[i] % self.__max_bbox_per_scale)
                bboxes_xywh[i][bbox_ind, :4] = bbox_xywh
                bbox_count[i] += 1

                exist_positive = True

        if not exist_positive:
            best_anchor_ind = np.argmax(np.array(iou).reshape(-1), axis=-1)
            best_detect = int(best_anchor_ind / self.__anchor_per_scale)

这段 我理解是一个gt与anchor box计算IOU当大于0.3时赋给对应的grid,如果再三个grid中都找不到大于0.3的IOU时才找一个最好的IOU的某一个grid中预测其他两个grid不再预测该物体,如果在三组anchor中,只在第一组找到大于0.3其他两组没有 则只在第一个grid中预测,其他的grid不再预测啊,这样理解对吗?为什么不是在三组anchor中,每一组找到最大的IOU然后三组对应的gris都预测该物体这样不是更好吗?谢谢您 for idx,match_id in enumerate(best_ious): group_idx=match_id//3 sub_idx=match_id%3 idx_x=np.floor(boxes[idx,0]grid_shapes[group_idx]).astype('int32') idx_y=np.floor(boxes[idx,1]grid_shapes[group_idx]).astype('int32')

y_true_list[group_idx][idx_y,idx_x,sub_idx,:2]=boxes[idx,0:2]
y_true_list[group_idx][idx_y,idx_x,sub_idx,2:4]=boxes[idx,2:4]
y_true_list[group_idx][idx_y,idx_x,sub_idx,4]=1.
y_true_list[group_idx][idx_y,idx_x,sub_idx,5+labels[idx]]=1.

return y_true_list 我看见这种写法 不知道两者有什么样的区别啊 谢谢

Stinky-Tofu commented 5 years ago

这几种做法对最终的性能影响很小

123lifei commented 5 years ago

@Stinky-Tofu 谢谢您的回答 那为什么会有这两种写法呢