示例#1
0
def prepare_testing_init(box, score):
    if cfg.ex_type == 'corner':
        i_it_4pys = snake_decode.get_init(box, init_type='corner')
    else:
        i_it_4pys = snake_decode.get_init(box)

    init_boxes = i_it_4pys
    i_it_4pys = uniform_upsample(i_it_4pys, snake_config.init_poly_num)
    c_it_4pys = img_poly_to_can_poly(i_it_4pys)

    if 0:
        print('--------- vis init-pts ---------')
        import matplotlib.pyplot as plt
        boxes = box.cpu().numpy()[0, ...]
        init_boxes = init_boxes.cpu().numpy()[0, ...]
        init_polys = i_it_4pys.cpu().numpy()[0, ...]
        I = np.zeros((100, 100))
        plt.imshow(I)
        for k in range(1):
            box = boxes[k]
            init_poly = init_polys[k, ...]
            init_box = init_boxes[k, ...]
            init_poly = np.concatenate((init_poly, init_poly[0:1, :]), axis=0)
            init_box = np.concatenate((init_box, init_box[0:1, :]), axis=0)
            plt.plot(init_box[:, 0], init_box[:, 1])
            plt.plot(init_poly[:15, 0], init_poly[:15, 1], 'r+')
        plt.show()
        exit()

    if 0:
        print('score.shape:', score.shape)
        print('i_it_4py.shape:', i_it_4pys.shape)

    ind = score > snake_config.ct_score
    if 0:
        print('ind:', ind)
        print('ind.shape:', ind.size())
        for k in range(ind.size(0)):
            a = torch.full([ind[k].sum()], k)
            print('a:', a)
    i_it_4pys = i_it_4pys[ind]
    c_it_4pys = c_it_4pys[ind]
    ind = torch.cat(
        [torch.full([ind[i].sum()], i) for i in range(ind.size(0))], dim=0)
    if 0:
        print('ind:', ind)
        exit()
    init = {'i_it_4py': i_it_4pys, 'c_it_4py': c_it_4pys, 'ind': ind}
    return init
示例#2
0
def prepare_training_box(ret, batch, init):
    box = ret['detection'][..., :4]
    score = ret['detection'][..., 4]
    batch_size = box.size(0)
    i_gt_4py = batch['i_gt_4py']
    ct_01 = batch['ct_01'].byte()
    ind = [
        get_box_match_ind(box[i], score[i], i_gt_4py[i][ct_01[i]])
        for i in range(batch_size)
    ]
    box_ind = [ind_[0] for ind_ in ind]
    gt_ind = [ind_[1] for ind_ in ind]

    i_it_4py = torch.cat([
        snake_decode.get_init(box[i][box_ind[i]][None])
        for i in range(batch_size)
    ],
                         dim=1)
    if i_it_4py.size(1) == 0:
        return

    i_it_4py = uniform_upsample(i_it_4py, snake_config.init_poly_num)[0]
    c_it_4py = img_poly_to_can_poly(i_it_4py)
    i_gt_4py = torch.cat(
        [batch['i_gt_4py'][i][gt_ind[i]] for i in range(batch_size)], dim=0)
    c_gt_4py = torch.cat(
        [batch['c_gt_4py'][i][gt_ind[i]] for i in range(batch_size)], dim=0)
    init_4py = {
        'i_it_4py': i_it_4py,
        'c_it_4py': c_it_4py,
        'i_gt_4py': i_gt_4py,
        'c_gt_4py': c_gt_4py
    }

    i_it_py = snake_decode.get_octagon(i_gt_4py[None])
    i_it_py = uniform_upsample(i_it_py, snake_config.poly_num)[0]
    c_it_py = img_poly_to_can_poly(i_it_py)
    i_gt_py = torch.cat(
        [batch['i_gt_py'][i][gt_ind[i]] for i in range(batch_size)], dim=0)
    init_py = {'i_it_py': i_it_py, 'c_it_py': c_it_py, 'i_gt_py': i_gt_py}

    ind = torch.cat(
        [torch.full([len(gt_ind[i])], i) for i in range(batch_size)], dim=0)

    if snake_config.train_pred_box_only:
        for k, v in init_4py.items():
            init[k] = v
        for k, v in init_py.items():
            init[k] = v
        init['4py_ind'] = ind
        init['py_ind'] = ind
    else:
        init.update(
            {k: torch.cat([init[k], v], dim=0)
             for k, v in init_4py.items()})
        init.update({'4py_ind': torch.cat([init['4py_ind'], ind], dim=0)})
        init.update(
            {k: torch.cat([init[k], v], dim=0)
             for k, v in init_py.items()})
        init.update({'py_ind': torch.cat([init['py_ind'], ind], dim=0)})
示例#3
0
def prepare_testing_init(box, score):
    i_it_4pys = snake_decode.get_init(box)
    i_it_4pys = uniform_upsample(i_it_4pys, snake_config.init_poly_num)
    c_it_4pys = img_poly_to_can_poly(i_it_4pys)

    ind = score > snake_config.ct_score
    i_it_4pys = i_it_4pys[ind]
    c_it_4pys = c_it_4pys[ind]
    ind = torch.cat([torch.full([ind[i].sum()], i) for i in range(ind.size(0))], dim=0)
    init = {'i_it_4py': i_it_4pys, 'c_it_4py': c_it_4pys, 'ind': ind}

    return init
示例#4
0
    def prepare_testing_init(self, output):
        i_it_4py = snake_decode.get_init(output['cp_box'][None])
        i_it_4py = snake_gcn_utils.uniform_upsample(i_it_4py,
                                                    snake_config.init_poly_num)
        c_it_4py = snake_gcn_utils.img_poly_to_can_poly(i_it_4py)

        i_it_4py = i_it_4py[0]
        c_it_4py = c_it_4py[0]
        ind = output['roi_ind'][output['cp_ind'].long()]
        init = {'i_it_4py': i_it_4py, 'c_it_4py': c_it_4py, 'ind': ind}
        output.update({'it_ex': init['i_it_4py']})

        return init
示例#5
0
def prepare_training_box(ret, batch, init):  #这里准备的是用于训练的bbox框
    box = ret['detection'][..., :4]
    # tmp_file = open('/home/tianhao.lu/code/Deep_snake/snake/Result/Contour/contour.log', 'w')
    # tmp_file.writelines("bbox:" + str(box) + "\n")
    # tmp_file.writelines(str("*************************************************************** \n"))
    # tmp_file.close()
    score = ret['detection'][..., 4]
    batch_size = box.size(0)
    i_gt_4py = batch['i_gt_4py']
    ct_01 = batch['ct_01'].byte()
    ind = [get_box_match_ind(box[i], score[i], i_gt_4py[i][ct_01[i]]) for i in range(batch_size)]
    box_ind = [ind_[0] for ind_ in ind]
    gt_ind = [ind_[1] for ind_ in ind]

    i_it_4py = torch.cat([snake_decode.get_init(box[i][box_ind[i]][None]) for i in range(batch_size)], dim=1)
    if i_it_4py.size(1) == 0:
        return

    i_it_4py = uniform_upsample(i_it_4py, snake_config.init_poly_num)[0]
    c_it_4py = img_poly_to_can_poly(i_it_4py)
    i_gt_4py = torch.cat([batch['i_gt_4py'][i][gt_ind[i]] for i in range(batch_size)], dim=0)
    c_gt_4py = torch.cat([batch['c_gt_4py'][i][gt_ind[i]] for i in range(batch_size)], dim=0)
    init_4py = {'i_it_4py': i_it_4py, 'c_it_4py': c_it_4py, 'i_gt_4py': i_gt_4py, 'c_gt_4py': c_gt_4py}

    i_it_py = snake_decode.get_octagon(i_gt_4py[None])
    i_it_py = uniform_upsample(i_it_py, snake_config.poly_num)[0]
    c_it_py = img_poly_to_can_poly(i_it_py)
    i_gt_py = torch.cat([batch['i_gt_py'][i][gt_ind[i]] for i in range(batch_size)], dim=0)
    init_py = {'i_it_py': i_it_py, 'c_it_py': c_it_py, 'i_gt_py': i_gt_py}

    ind = torch.cat([torch.full([len(gt_ind[i])], i) for i in range(batch_size)], dim=0)

    if snake_config.train_pred_box_only:
        for k, v in init_4py.items():
            init[k] = v
        for k, v in init_py.items():
            init[k] = v
        init['4py_ind'] = ind
        init['py_ind'] = ind
    else:
        init.update({k: torch.cat([init[k], v], dim=0) for k, v in init_4py.items()})
        init.update({'4py_ind': torch.cat([init['4py_ind'], ind], dim=0)})
        init.update({k: torch.cat([init[k], v], dim=0) for k, v in init_py.items()})
        init.update({'py_ind': torch.cat([init['py_ind'], ind], dim=0)})
示例#6
0
def prepare_testing_init(box, score):
    i_it_4pys = snake_decode.get_init(box)
    i_it_4pys = uniform_upsample(i_it_4pys, snake_config.init_poly_num)
    c_it_4pys = img_poly_to_can_poly(i_it_4pys)

    #ind=[batch][t,f,t,f...]
    ind = score > snake_config.ct_score

    i_it_4pys = i_it_4pys[ind]
    c_it_4pys = c_it_4pys[ind]

    #torch.full([ind[i].sum()], i)->[i,i...i] 长度为这张图片score > snake_config.ct_score的个数

    # ind=    [0,0,0...,0]
    #         [1,1,1...,1]
    #         [2,2,2...,2]
    #         [3,3,3...,3]
    #ind[n]为第n张图片的...
    ind = torch.cat(
        [torch.full([ind[i].sum()], i) for i in range(ind.size(0))], dim=0)

    init = {'i_it_4py': i_it_4pys, 'c_it_4py': c_it_4pys, 'ind': ind}

    return init