if name == 'main':
parser = argparse.ArgumentParser()
parser.add_argument('--restore_ckpt', help="restore checkpoint", default=r"D:\jx\ai\stereo_match_dl\IGEV-main\IGEV-main\IGEV-Stereo\ckpt\41481_epoch_igev-stereo.pth")
# parser.add_argument('-l', '--left_imgs', help="path to all first (left) frames", default=r"D:\jx\ai\stereo_match_dl\test_image\bak\SV1-02_20190416_L1B0000976744_8041900187280009_01-PAN2_epi.tif")
# parser.add_argument('-r', '--right_imgs', help="path to all second (right) frames", default=r"D:\jx\ai\stereo_match_dl\test_image\bak\SV1-02_20190416_L1B0000976744_8041900187280009_01-PAN1_epi.tif")
parser.add_argument('-l', '--left_imgs', help="path to all first (left) frames", default=r"D:\jx\ai\stereo_match_dl\test_image\bak\SV1_PAN1_down_half_resized.tif")
parser.add_argument('-r', '--right_imgs', help="path to all second (right) frames", default=r"D:\jx\ai\stereo_match_dl\test_image\bak\SV1_PAN2_down_half_resized.tif")
code
# parser.add_argument('-l', '--left_imgs', help="path to all first (left) frames", default=r"D:\jx\ai\stereo_match_dl\test_image\right\3_6_right.tif")
# parser.add_argument('-r', '--right_imgs', help="path to all second (right) frames", default=r"D:\jx\ai\stereo_match_dl\test_image\left\3_6_left.tif")
#parser.add_argument('-l', '--left_imgs', help="path to all first (left) frames", default=r"D:\jx\ai\stereo_match_dl\train_image\experimental data\with ground truth\test\left\HY_left_0.tiff")
#parser.add_argument('-r', '--right_imgs', help="path to all second (right) frames", default=r"D:\jx\ai\stereo_match_dl\train_image\experimental data\with ground truth\test\right\HY_right_0.tiff")
parser.add_argument('--output_directory', help="directory to save output", default=r"D:\jx\ai\stereo_match_dl\IGEV-main\IGEV-main\IGEV-Stereo\core\demo-output\test_patch")
parser.add_argument('--mixed_precision', action='store_true', help='use mixed precision')
# Architecture choices
parser.add_argument('--hidden_dims', nargs='+', type=int, default=[128]*3, help="hidden state and context dimensions")
parser.add_argument('--corr_implementation', choices=["reg", "alt", "reg_cuda", "alt_cuda"], default="reg", help="correlation volume implementation")
parser.add_argument('--shared_backbone', action='store_true', help="use a single backbone for the context and feature encoders")
parser.add_argument('--corr_levels', type=int, default=2, help="number of levels in the correlation pyramid")
parser.add_argument('--corr_radius', type=int, default=4, help="width of the correlation pyramid")
parser.add_argument('--n_downsample', type=int, default=2, help="resolution of the disparity field (1/2^K)")
parser.add_argument('--slow_fast_gru', action='store_true', help="iterate the low-res GRUs more frequently")
parser.add_argument('--n_gru_layers', type=int, default=3, help="number of hidden GRU levels")
parser.add_argument('--max_disp', type=int, default=192, help="max disp of geometry encoding volume")
args = parser.parse_args()
Path(args.output_directory).mkdir(exist_ok=True, parents=True)
# 初始化模型
model = torch.nn.DataParallel(IGEVStereo(args), device_ids=[0])
model.load_state_dict(torch.load(args.restore_ckpt))
model = model.module
model.to(DEVICE)
model.eval()
result = get_init_disp(args.left_imgs,args.right_imgs,model)
get_disp_img_pyramid(model, args.left_imgs,args.right_imgs, result ,args.output_directory)