コード例 #1
0
ファイル: test_nyu_metric.py プロジェクト: spcolin/refine
def test(model_path):
    test_args = TestOptions().parse()
    test_args.thread = 0
    test_args.batchsize = 1
    merge_cfg_from_file(test_args)

    data_loader = CustomerDataLoader(test_args)
    test_datasize = len(data_loader)
    logger.info('{:>15}: {:<30}'.format('test_data_size', test_datasize))
    # load model
    model = MetricDepthModel()

    model.eval()

    test_args.load_ckpt = model_path

    # load checkpoint
    if test_args.load_ckpt:
        load_ckpt(test_args, model)
    model.cuda()
    # model = torch.nn.DataParallel(model)

    # test
    smoothed_absRel = SmoothedValue(test_datasize)
    smoothed_rms = SmoothedValue(test_datasize)
    smoothed_logRms = SmoothedValue(test_datasize)
    smoothed_squaRel = SmoothedValue(test_datasize)
    smoothed_silog = SmoothedValue(test_datasize)
    smoothed_silog2 = SmoothedValue(test_datasize)
    smoothed_log10 = SmoothedValue(test_datasize)
    smoothed_delta1 = SmoothedValue(test_datasize)
    smoothed_delta2 = SmoothedValue(test_datasize)
    smoothed_delta3 = SmoothedValue(test_datasize)
    smoothed_whdr = SmoothedValue(test_datasize)

    smoothed_criteria = {
        'err_absRel': smoothed_absRel,
        'err_squaRel': smoothed_squaRel,
        'err_rms': smoothed_rms,
        'err_silog': smoothed_silog,
        'err_logRms': smoothed_logRms,
        'err_silog2': smoothed_silog2,
        'err_delta1': smoothed_delta1,
        'err_delta2': smoothed_delta2,
        'err_delta3': smoothed_delta3,
        'err_log10': smoothed_log10,
        'err_whdr': smoothed_whdr
    }

    for i, data in enumerate(data_loader):
        out = model.inference(data)
        pred_depth = torch.squeeze(out['b_fake'])
        img_path = data['A_paths']
        invalid_side = data['invalid_side'][0]
        pred_depth = pred_depth[invalid_side[0]:pred_depth.size(0) -
                                invalid_side[1], :]
        pred_depth = pred_depth / data['ratio'].cuda()  # scale the depth
        pred_depth = resize_image(pred_depth,
                                  torch.squeeze(data['B_raw']).shape)
        smoothed_criteria = evaluate_err(pred_depth,
                                         data['B_raw'],
                                         smoothed_criteria,
                                         mask=(45, 471, 41, 601),
                                         scale=10.)

        # save images
        model_name = test_args.load_ckpt.split('/')[-1].split('.')[0]
        image_dir = os.path.join(cfg.ROOT_DIR, './evaluation',
                                 cfg.MODEL.ENCODER, model_name)
        if not os.path.exists(image_dir):
            os.makedirs(image_dir)
        img_name = img_path[0].split('/')[-1]
        #plt.imsave(os.path.join(image_dir, 'd_' + img_name), pred_depth, cmap='rainbow')
        #cv2.imwrite(os.path.join(image_dir, 'rgb_' + img_name), data['A_raw'].numpy().squeeze())

        # print('processing (%04d)-th image... %s' % (i, img_path))

    # print("###############absREL ERROR: %f", smoothed_criteria['err_absRel'].GetGlobalAverageValue())
    # print("###############silog ERROR: %f", np.sqrt(smoothed_criteria['err_silog2'].GetGlobalAverageValue() - (
    #     smoothed_criteria['err_silog'].GetGlobalAverageValue()) ** 2))
    # print("###############log10 ERROR: %f", smoothed_criteria['err_log10'].GetGlobalAverageValue())
    # print("###############RMS ERROR: %f", np.sqrt(smoothed_criteria['err_rms'].GetGlobalAverageValue()))
    # print("###############delta_1 ERROR: %f", smoothed_criteria['err_delta1'].GetGlobalAverageValue())
    # print("###############delta_2 ERROR: %f", smoothed_criteria['err_delta2'].GetGlobalAverageValue())
    # print("###############delta_3 ERROR: %f", smoothed_criteria['err_delta3'].GetGlobalAverageValue())
    # print("###############squaRel ERROR: %f", smoothed_criteria['err_squaRel'].GetGlobalAverageValue())
    # print("###############logRms ERROR: %f", np.sqrt(smoothed_criteria['err_logRms'].GetGlobalAverageValue()))

    f.write("tested model:" + model_path)
    f.write('\n')
    f.write("###############absREL ERROR:" +
            str(smoothed_criteria['err_absRel'].GetGlobalAverageValue()))
    f.write('\n')
    f.write("###############silog ERROR:" + str(
        np.sqrt(smoothed_criteria['err_silog2'].GetGlobalAverageValue() -
                (smoothed_criteria['err_silog'].GetGlobalAverageValue())**2)))
    f.write('\n')
    f.write("###############log10 ERROR:" +
            str(smoothed_criteria['err_log10'].GetGlobalAverageValue()))
    f.write('\n')
    f.write("###############RMS ERROR:" +
            str(np.sqrt(smoothed_criteria['err_rms'].GetGlobalAverageValue())))
    f.write('\n')
    f.write("###############delta_1 ERROR:" +
            str(smoothed_criteria['err_delta1'].GetGlobalAverageValue()))
    f.write('\n')
    f.write("###############delta_2 ERROR:" +
            str(smoothed_criteria['err_delta2'].GetGlobalAverageValue()))
    f.write('\n')
    f.write("###############delta_3 ERROR:" +
            str(smoothed_criteria['err_delta3'].GetGlobalAverageValue()))
    f.write('\n')
    f.write("###############squaRel ERROR:" +
            str(smoothed_criteria['err_squaRel'].GetGlobalAverageValue()))
    f.write('\n')
    f.write(
        "###############logRms ERROR:" +
        str(np.sqrt(smoothed_criteria['err_logRms'].GetGlobalAverageValue())))
    f.write('\n')
    f.write(
        '-----------------------------------------------------------------------------'
    )
    f.write('\n')
コード例 #2
0
        'err_logRms': smoothed_logRms,
        'err_silog2': smoothed_silog2,
        'err_delta1': smoothed_delta1,
        'err_delta2': smoothed_delta2,
        'err_delta3': smoothed_delta3,
        'err_log10': smoothed_log10
    }

    for i, data in enumerate(data_loader):
        out = model.module.inference_kitti(data)
        pred_depth = np.squeeze(out['b_fake'])
        img_path = data['A_paths']

        if len(data['B_raw'].shape) != 2:
            smoothed_criteria = evaluate_err(pred_depth,
                                             data['B_raw'],
                                             smoothed_criteria,
                                             scale=80.)
            print('processing (%04d)-th image... %s' % (i, img_path))
            print(smoothed_criteria['err_absRel'].GetGlobalAverageValue())
        #save_images(data, pred_depth, scale=256.*80.)

    if len(data['B_raw'].shape) != 2:
        print("###############absREL ERROR: %f",
              smoothed_criteria['err_absRel'].GetGlobalAverageValue())
        print(
            "###############silog ERROR: %f",
            np.sqrt(smoothed_criteria['err_silog2'].GetGlobalAverageValue() - (
                smoothed_criteria['err_silog'].GetGlobalAverageValue())**2))
        print("###############log10 ERROR: %f",
              smoothed_criteria['err_log10'].GetGlobalAverageValue())
        print("###############RMS ERROR: %f",
コード例 #3
0
        'err_whdr': smoothed_whdr
    }

    for i, data in enumerate(data_loader):
        out = model.module.inference(data)
        pred_depth = torch.squeeze(out['b_fake'])
        img_path = data['A_paths']
        invalid_side = data['invalid_side'][0]
        pred_depth = pred_depth[invalid_side[0]:pred_depth.size(0) -
                                invalid_side[1], :]
        pred_depth = pred_depth / data['ratio'].cuda()  # scale the depth
        pred_depth = resize_image(pred_depth,
                                  torch.squeeze(data['B_raw']).shape)
        smoothed_criteria = evaluate_err(pred_depth,
                                         data['B_raw'],
                                         smoothed_criteria,
                                         mask=(45, 471, 41, 601),
                                         scale=10.)

        # save images
        model_name = test_args.load_ckpt.split('/')[-1].split('.')[0]
        image_dir = os.path.join(cfg.ROOT_DIR, './evaluation',
                                 cfg.MODEL.ENCODER, model_name)
        if not os.path.exists(image_dir):
            os.makedirs(image_dir)
        img_name = img_path[0].split('/')[-1]
        #plt.imsave(os.path.join(image_dir, 'd_' + img_name), pred_depth, cmap='rainbow')
        #cv2.imwrite(os.path.join(image_dir, 'rgb_' + img_name), data['A_raw'].numpy().squeeze())

        print('processing (%04d)-th image... %s' % (i, img_path))
コード例 #4
0
    bg_smoothed_silog2 = SmoothedValue(test_datasize)
    bg_smoothed_log10 = SmoothedValue(test_datasize)
    bg_smoothed_delta1 = SmoothedValue(test_datasize)
    bg_smoothed_delta2 = SmoothedValue(test_datasize)
    bg_smoothed_delta3 = SmoothedValue(test_datasize)
    bg_smoothed_criteria = {'err_absRel':bg_smoothed_absRel, 'err_squaRel': bg_smoothed_squaRel, 'err_rms': bg_smoothed_rms,
                         'err_silog': bg_smoothed_silog, 'err_logRms': bg_smoothed_logRms, 'err_silog2': bg_smoothed_silog2,
                         'err_delta1': bg_smoothed_delta1, 'err_delta2': bg_smoothed_delta2, 'err_delta3': bg_smoothed_delta3,
                         'err_log10': bg_smoothed_log10}
    for i, data in enumerate(data_loader):
        out = model.module.inference_kitti(data)
        pred_depth = np.squeeze(out['b_fake'])
        img_path = data['A_paths']

        if len(data['B_raw'].shape) != 2:
            smoothed_criteria = evaluate_err(pred_depth, data['B_raw'], smoothed_criteria, scale=80.)
            rois_smoothed_criteria = evaluate_err(pred_depth, data['B_raw_rois'], rois_smoothed_criteria, scale=80.)
            bg_smoothed_criteria = evaluate_err(pred_depth, data['B_raw_bg'], bg_smoothed_criteria, scale=80.)
            print('processing (%04d)-th image... %s' % (i, img_path))
            print(smoothed_criteria['err_absRel'].GetGlobalAverageValue())
        save_images(data, pred_depth, scale=256.*80.)


    LOG_FOUT = open(os.path.join('object_val_results.txt'), 'w')
    def log_string(out_str):
        LOG_FOUT.write(out_str+'\n')
        LOG_FOUT.flush()
        print(out_str)


    if len(data['B_raw'].shape) != 2: