Exemplo n.º 1
0
                % i)
            disp_gt[disp_gt == np.inf] = .0
            #disp = readPFM('/media/ccjData2/research-projects/GCNet/results/gcnet-F8-RMSp-sfF3k-epo31-4dsConv-k5-testKT15/disp-epo-030/%06d_10.pfm' %i)
            disp = readPFM(
                '/home/ccj/atten-stereo/results/ganet-sfepo10-kt15epo100/val-30/%06d_10.pfm'
                % i)
            disp[disp == np.inf] = .0
            rst_disp = KT15FalseClr.writeKT15FalseColor(disp).astype(np.uint8)
            rst_disp_gt = KT15FalseClr.writeKT15FalseColor(disp_gt).astype(
                np.uint8)
            show_uint8(rst_disp, title='disp_kt15_false_color')
            show_uint8(rst_disp_gt, title='disp_gt_kt15_false_color')
            err = np.abs(disp_gt - disp)
            rst_err = KT15LogClr.writeKT15ErrorDispLogColor(disp, disp_gt)
            show_uint8(rst_err, title='err_kt15_log_color')
            show(err, title='err gray color')

        time_elapsed = time.time() - since
        print('Training complete in {:.0f}s'.format(time_elapsed))


# see the GPU runtime counting code from https://github.com/sacmehta/ESPNet/issues/57;
def computeTime(model, device='cuda'):
    inputs = torch.randn(1, 3, 512, 1024)
    if device == 'cuda':
        model = model.cuda()
        inputs = inputs.cuda()

    model.eval()
    i = 0
    time_spent = []
Exemplo n.º 2
0
    def __postprocessing_mem(self, imgl, imgr, cost, direction, display=False):

        post.InitCUDA()
        start = time.time()

        cross_array_init = np.zeros(
            (4, imgl.shape[0], imgl.shape[1])).astype(np.float32)
        imgl_d = post.CUDA_float_array(imgl)
        imgr_d = post.CUDA_float_array(imgr)

        leftc_d = post.CUDA_float_array(cross_array_init)
        rightc_d = post.CUDA_float_array(cross_array_init)

        post.cross(imgl_d, leftc_d, self.__L1, self.__tau1)
        post.cross(imgr_d, rightc_d, self.__L1, self.__tau1)

        cost_d = post.CUDA_double_array(cost)
        temp_cost_d = post.CUDA_double_array(cost)

        post.swap_axis_back(cost_d, temp_cost_d)
        post.CUDA_copy_double(temp_cost_d, cost_d)

        for i in range(0, self.__cbca_i1):
            post.cbca(leftc_d, rightc_d, cost_d, temp_cost_d, direction)
            post.CUDA_copy_double(temp_cost_d, cost_d)
        if display:
            print "CBCA 1"
            cc = cost_d.get_array()
            ddisp = np.argmin(cc, axis=0)
            pfm.show(ddisp)

        post.swap_axis(cost_d, temp_cost_d)
        post.CUDA_copy_double(temp_cost_d, cost_d)

        tmp = np.zeros((cost.shape[1], cost.shape[2]))
        tmp_d = post.CUDA_double_array(tmp)

        for i in range(0, self.__sgm_i):
            temp_cost_d.set_to_zero()
            tmp_d.set_to_zero()
            post.sgm(imgl_d, imgr_d, cost_d, temp_cost_d, tmp_d, self.__pi1,
                     self.__pi2, self.__tau_so, self.__alpha1, self.__sgm_q1,
                     self.__sgm_q2, direction)
            post.CUDA_divide_double(temp_cost_d, 4)
            post.CUDA_copy_double(temp_cost_d, cost_d)

        post.swap_axis_back(cost_d, temp_cost_d)
        post.CUDA_copy_double(temp_cost_d, cost_d)

        if display:
            print "SGM"
            cc = cost_d.get_array()
            ddisp = np.argmin(cc, axis=0)
            pfm.show(ddisp)

        for i in range(0, self.__cbca_i2):
            post.cbca(leftc_d, rightc_d, cost_d, temp_cost_d, direction)

            post.CUDA_copy_double(temp_cost_d, cost_d)

        if display:
            print "CBCA2"
            cc = cost_d.get_array()
            ddisp = np.argmin(cc, axis=0)
            pfm.show(ddisp)

        cc = cost_d.get_array()
        disp_l = np.argmin(cc, axis=0).astype(np.float32)
        out_s = cc.shape[0]
        del cc

        disp_d = post.CUDA_float_array(disp_l)
        disp_temp = post.CUDA_float_array(disp_l)

        post.subpixel_enchancement(disp_d, cost_d, disp_temp)

        post.CUDA_copy_float(disp_temp, disp_d)
        if display:
            disp = disp_d.get_array()
            print "Subpixel"
            pfm.show(disp)

        for i in range(0, self.__median_i):
            disp = post.median2d(disp_d, disp_temp, self.__median_w)
            post.CUDA_copy_float(disp_temp, disp_d)

        if display:
            disp = disp_d.get_array()
            print "Median"
            pfm.show(disp)

        post.mean2d(disp_d, disp_temp, self.__gaussian(self.__blur_sigma),
                    self.__blur_t)
        post.CUDA_copy_float(disp_temp, disp_d)

        if display:
            disp = disp_d.get_array()
            print "Bilateral"
            pfm.show(disp)

        disp = disp_d.get_array()

        end = time.time()
        print(end - start)

        return disp