예제 #1
0
def edge_detect_hed_ori_e(im,
                          net_ori,
                          edge_res,
                          ori_name='upscore-fuse-edge-occ'):
    in_ = caffeTransform(im)
    resedge = {}

    net_ori.blobs['data'].reshape(1, *in_.shape)
    net_ori.blobs['data'].data[...] = in_
    #    print net_ori.blobs['data'].shape
    h, w = edge_res.shape
    edge_res = edge_res.reshape((1, h, w))
    net_ori.blobs['res_edge'].reshape(1, *edge_res.shape)
    net_ori.blobs['res_edge'].data[...] = edge_res
    #   print net_ori.blobs['res_edge'].shape

    net_ori.forward()
    # add back the oritation results
    resedge['occmap'] = net_ori.blobs[ori_name].data[0][0, :, :]

    for iedge in range(3, 6):
        name_save = 'theta' + '{}'.format(iedge)
        name_type = 'upscore-dsn' + '{}'.format(iedge) + '-occ'
        resedge[name_save] = net_ori.blobs[name_type].data[0][0, :, :]
    return resedge
예제 #2
0
def edge_detect_hed_ori(im,
                        net,
                        net_ori,
                        w_edge=0,
                        ori_name='upscore-fuse-occ',
                        para={'scales': [1.0]}):
    resedge = {}
    for scale in para['scales']:
        append = ''
        img = im
        if scale != 1.0:
            img = scm.imresize(im, scale)
            append = '_{0:.2f}'.format(scale)
            append = append.replace(".", "")
        print append

        in_ = caffeTransform(img)
        #print in_.shape
        net_ori.blobs['data'].reshape(1, *in_.shape)
        net_ori.blobs['data'].data[...] = in_
        net_ori.forward()
        if w_edge:
            edgepred = edge_hed(in_, net, 0, append)
            resedge['edgemap' + append] = edgepred['edgemap' + append].copy()

        # add back the oritation results
        res_name = 'occmap' + append
        resedge[res_name] = net_ori.blobs[ori_name].data[0][0, :, :].copy()


#    for iedge in range(3,6):
#        name_save = 'theta'+'{}'.format(iedge)
#        name_type = 'upscore-dsn'+'{}'.format(iedge)+'-occ'
#        resedge[name_save] = net_ori.blobs[name_type].data[0][0,:,:]
    return resedge
예제 #3
0
def edge_detect_cls_4ori_deeplab(im, net, ori_name='prob_ori'):
    resedge = {}
    in_ = caffeTransform(im)
    net.blobs['data'].reshape(1, *in_.shape)
    net.blobs['data'].data[...] = in_
    net.forward()
    res_name = 'occmap'
    resedge[res_name] = net.blobs[ori_name].data[0][0, :, :]
    return resedge
예제 #4
0
def edge_detect_parsenet_ori(im, net):
    in_ = caffeTransform(im)
    net.blobs['data'].reshape(1, *in_.shape)
    net.blobs['data'].data[...] = in_
    net.forward()
    print net.blobs['score_occ'].data[0].shape
    resedge = {}
    resedge['occmap'] = net.blobs['score_occ'].data[0][0, :, :]
    return resedge
예제 #5
0
def edge_detect_hed_wcls(im, net):
    in_ = caffeTransform(im)
    net.blobs['data'].reshape(1, *in_.shape)
    net.blobs['data'].data[...] = in_
    net.forward()
    resedge = {}
    resedge['clsmap'] = net.blobs['prob'].data[0]
    resedge['edgemap_hed'] = net.blobs['sigmoid-fuse'].data[0][0, :, :]
    resedge['edgemap_sem'] = net.blobs['score_prob'].data[0][0, :, :]
    resedge['edgemap'] = net.blobs['sigmoid-joint'].data[0][0, :, :]
    return resedge
예제 #6
0
def edge_detect_hed_fb(im, net, net_ori):
    in_ = caffeTransform(im)
    resedge = {}
    if net:
        resedge = edge_hed(in_, net)

    net_ori.blobs['data'].reshape(1, *in_.shape)
    net_ori.blobs['data'].data[...] = in_
    net_ori.forward()
    resedge['occmap'] = net_ori.blobs['softmax_fuse_occ'].data[0]
    return resedge
예제 #7
0
def edge_detect_ori_deeplab(im, net, ori_name='fc_fusion_occ'):
    # only predict orientation
    resedge = {}
    in_ = caffeTransform(im)
    net.blobs['data'].reshape(1, *in_.shape)
    net.blobs['data'].data[...] = in_
    net.forward()
    res_name = 'occmap'
    resedge[res_name] = net.blobs[ori_name].data[0][0, :, :]
    resedge['occmap4'] = net.blobs['uppool4_ms_occ'].data[0][0, :, :]
    resedge['occmap8'] = net.blobs['upfc8_ms_occ'].data[0][0, :, :]
    resedge['occmapmean'] = 0.5 * resedge['occmap4'] + 0.5 * resedge['occmap8']
    return resedge
예제 #8
0
def edge_detect_deeplab(im, net):
    # joint predict edge + orientation
    in_ = caffeTransform(im)
    net.blobs['data'].reshape(1, *in_.shape)
    net.blobs['data'].data[...] = in_
    net.forward()
    resedge = {}
    if 'fc_fusion_occ' in net.blobs.keys():
        resedge['occmap'] = net.blobs['fc_fusion_occ'].data[0][0, :, :]
        resedge['occmap8'] = net.blobs['upfc8_ms_occ'].data[0][0, :, :]
        resedge['occmap4'] = net.blobs['uppool4_ms_occ'].data[0][0, :, :]

    if 'sigmoid_fuse' in net.blobs.keys():
        resedge['edgemap'] = net.blobs['sigmoid_fuse'].data[0][0, :, :]
    # side output

    return resedge
예제 #9
0
def edge_detect_hed(im, net):
    in_ = caffeTransform(im)
    net.blobs['data'].reshape(1, *in_.shape)
    net.blobs['data'].data[...] = in_
    net.forward()
    resedge = {}
    resedge['edgemap'] = net.blobs['sigmoid-fuse'].data[0][0, :, :]
    resedge['occmap'] = net.blobs['upscore-fuse-occ'].data[0][0, :, :]
    # save the response of each layer
    # for edge map
    for iedge in range(1, 6):
        name_type = 'sigmoid-dsn' + '{}'.format(iedge)
        name_save = 'edge' + '{}'.format(iedge)
        resedge[name_save] = net.blobs[name_type].data[0][0, :, :]
    for iedge in range(3, 6):
        name_save = 'theta' + '{}'.format(iedge)
        name_type = 'upscore-dsn' + '{}'.format(iedge) + '-occ'
        resedge[name_save] = net.blobs[name_type].data[0][0, :, :]
    return resedge