def __init__(self):
        print("开始进行测试")

        self.param_gpu_id = 0
        self.param_single_channel = True
        self.param_threshold = 3
        self.param_batch_size = 1
        self.param_use_cvpr = False
        self.param_use_cnn = True
        self.param_use_traditional = True
        self.param_use_combine = True
        self.param_save_mat = False
        # 加载模型
        os.environ["CUDA_VISIBLE_DEVICES"] = str(self.param_gpu_id)
        self.use_cuda = torch.cuda.is_available()

        print(self.param_gpu_id, self.param_single_channel,
              self.param_threshold, self.param_batch_size)
        if self.param_single_channel:
            if self.use_cuda:
                param_checkpoint_path = '/home/zlk/project/registration_cnn_ntg/trained_weight/output/voc2012_coco2014_NTG_resnet101.pth.tar'
            else:
                param_checkpoint_path = '/Users/zale/project/myself/registration_cnn_ntg/trained_weight/output/voc2012_coco2014_NTG_resnet101.pth.tar'

        else:
            param_checkpoint_path = '/mnt/4T/zlk/trained_weights/best_checkpoint_coco2017_multi_gpu_paper30_NTG_resnet101.pth.tar'

        if self.param_use_cnn:
            self.ntg_model = createModel(
                param_checkpoint_path,
                use_cuda=self.use_cuda,
                single_channel=self.param_single_channel)
            self.ntg_model.eval()
        else:
            self.ntg_model = None

        if self.param_use_cvpr:
            self.cvpr_model = createCVPRModel(use_cuda=self.use_cuda)
            self.cvpr_model.eval()
        else:
            self.cvpr_model = None
예제 #2
0
def main():

    single_channel = False
    print("开始进行测试")
    os.environ["CUDA_VISIBLE_DEVICES"] = "0"

    ntg_checkpoint_path = '/mnt/4T/zlk/trained_weights/best_checkpoint_coco2017_multi_gpu_paper30_NTG_resnet101.pth.tar'
    #test_image_path = '/home/zlk/datasets/coco_test2017'
    # test_image_path = '/mnt/4T/zlk/datasets/mulitspectral/Harvard'
    test_image_path = '/mnt/4T/zlk/datasets/mulitspectral/complete_ms_data_mat'

    threshold = 3
    batch_size = 1
    # 加载模型
    use_cuda = torch.cuda.is_available()

    # vis = VisdomHelper(env_name='Harvard_test')
    vis = VisdomHelper(env_name='CAVE_test')

    ntg_model = createModel(ntg_checkpoint_path,
                            use_cuda=use_cuda,
                            single_channel=single_channel)
    cvpr_model = createCVPRModel(use_cuda=use_cuda)

    print('测试harvard网格点损失')
    dataloader, pair_generator = createDataloader(
        test_image_path,
        batch_size,
        use_cuda=use_cuda,
        single_channel=single_channel)

    iterDataset(dataloader,
                pair_generator,
                ntg_model,
                cvpr_model,
                vis,
                threshold=threshold,
                use_cuda=use_cuda)
    param_test_image_path = '/mnt/4T/zlk/datasets/mulitspectral/complete_ms_data_mat'
    # param_test_image_path = '/home/zale/datasets/complete_ms_data_mat'
    # param_test_image_path = '/Users/zale/project/datasets/complete_ms_data_mat'

    # 加载模型
    os.environ["CUDA_VISIBLE_DEVICES"] = str(param_gpu_id)
    use_cuda = torch.cuda.is_available()

    if param_use_cnn:
        ntg_model = createModel(param_checkpoint_path,
                                use_cuda=use_cuda,
                                single_channel=param_single_channel)
    else:
        ntg_model = None

    cvpr_model = createCVPRModel(use_cuda=use_cuda)

    print('测试cave网格点损失')
    dataloader, pair_generator = createDataloader(
        param_test_image_path,
        batch_size=param_batch_size,
        single_channel=param_single_channel,
        use_cuda=use_cuda)

    iterDataset(dataloader,
                pair_generator,
                ntg_model,
                cvpr_model,
                vis,
                threshold=param_threshold,
                use_cuda=use_cuda,
    def register_showVisdom(self):
        print("开始进行测试")

        param_gpu_id = 0
        param_single_channel = True
        param_threshold = 3
        param_batch_size = 1
        param_use_cvpr = True
        param_use_cnn = True
        param_use_traditional = True
        param_use_combine = True
        param_save_mat = False

        print(param_gpu_id, param_single_channel, param_threshold,
              param_batch_size)

        vis = VisdomHelper(env_name='CAVE_common', port=8098)

        if param_single_channel:
            param_checkpoint_path = '/home/zlk/project/registration_cnn_ntg/trained_weight/output/voc2012_coco2014_NTG_resnet101.pth.tar'
        else:
            param_checkpoint_path = '/mnt/4T/zlk/trained_weights/best_checkpoint_coco2017_multi_gpu_paper30_NTG_resnet101.pth.tar'

        param_test_image_path = '/mnt/4T/zlk/datasets/mulitspectral/complete_ms_data_mat'
        # param_test_image_path = '/home/zale/datasets/complete_ms_data_mat'
        # param_test_image_path = '/Users/zale/project/datasets/complete_ms_data_mat'

        # 加载模型
        os.environ["CUDA_VISIBLE_DEVICES"] = str(param_gpu_id)
        use_cuda = torch.cuda.is_available()

        if param_use_cnn:
            ntg_model = createModel(param_checkpoint_path,
                                    use_cuda=use_cuda,
                                    single_channel=param_single_channel)
        else:
            ntg_model = None

        cvpr_model = createCVPRModel(use_cuda=use_cuda)

        source_image_path = '../datasets/row_data/multispectral/door2.jpg'
        target_image_path = '../datasets/row_data/multispectral/door1.jpg'

        source_image_raw = io.imread(source_image_path)
        target_image_raw = io.imread(target_image_path)

        source_image = source_image_raw[:, :, 0:1]
        target_image = target_image_raw[:, :, 2:3]

        source_image_var = preprocess_image(source_image,
                                            resize=True,
                                            use_cuda=use_cuda)
        target_image_var = preprocess_image(target_image,
                                            resize=True,
                                            use_cuda=use_cuda)

        batch = {
            'source_image': source_image_var,
            'target_image': target_image_var
        }

        ntg_model.eval()
        theta = ntg_model(batch)
        # theta_opencv = theta2param(theta.view(-1, 2, 3), 240, 240, use_cuda=use_cuda)
        # cnn_ntg_param_batch = estimate_param_batch(source_image_var[:, 0, :, :], target_image_var[:, 2, :, :], theta_opencv)

        cnn_image_warped_batch = affine_transform_pytorch(
            source_image_var, theta)

        vis.showImageBatch(source_image_var,
                           normailze=True,
                           win='source_image_batch',
                           title='source_image_batch')
        vis.showImageBatch(target_image_var,
                           normailze=True,
                           win='target_image_batch',
                           title='target_image_batch')
        vis.showImageBatch(cnn_image_warped_batch,
                           normailze=True,
                           win='cnn_image_warped_batch',
                           title='cnn_image_warped_batch')