forked from qinzheng93/GeoTransformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ce888d
commit 2232c06
Showing
8 changed files
with
143 additions
and
45 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
91 changes: 91 additions & 0 deletions
91
experiments/geotransformer.3dmatch.stage4.gse.k3.max.oacl.stage2.sinkhorn/demo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import argparse | ||
|
||
import torch | ||
import numpy as np | ||
|
||
from geotransformer.utils.data import registration_collate_fn_stack_mode | ||
from geotransformer.utils.torch import to_cuda, release_cuda | ||
from geotransformer.utils.open3d import make_open3d_point_cloud, get_color, draw_geometries | ||
from geotransformer.utils.registration import compute_registration_error | ||
|
||
from config import make_cfg | ||
from model import create_model | ||
|
||
|
||
def make_parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--src_file", required=True, help="src point cloud numpy file") | ||
parser.add_argument("--ref_file", required=True, help="src point cloud numpy file") | ||
parser.add_argument("--gt_file", required=True, help="ground-truth transformation file") | ||
parser.add_argument("--weights", required=True, help="model weights file") | ||
return parser | ||
|
||
|
||
def load_data(args): | ||
src_points = np.load(args.src_file) | ||
ref_points = np.load(args.ref_file) | ||
src_feats = np.ones_like(src_points[:, :1]) | ||
ref_feats = np.ones_like(ref_points[:, :1]) | ||
|
||
data_dict = { | ||
"ref_points": ref_points.astype(np.float32), | ||
"src_points": src_points.astype(np.float32), | ||
"ref_feats": ref_feats.astype(np.float32), | ||
"src_feats": src_feats.astype(np.float32), | ||
} | ||
|
||
if args.gt_file is not None: | ||
transform = np.load(args.gt_file) | ||
data_dict["transform"] = transform.astype(np.float32) | ||
|
||
return data_dict | ||
|
||
|
||
def main(): | ||
parser = make_parser() | ||
args = parser.parse_args() | ||
|
||
cfg = make_cfg() | ||
|
||
# prepare data | ||
data_dict = load_data(args) | ||
neighbor_limits = [38, 36, 36, 38] # default setting in 3DMatch | ||
data_dict = registration_collate_fn_stack_mode( | ||
[data_dict], cfg.backbone.num_stages, cfg.backbone.init_voxel_size, cfg.backbone.init_radius, neighbor_limits | ||
) | ||
|
||
# prepare model | ||
model = create_model(cfg).cuda() | ||
state_dict = torch.load(args.weights) | ||
model.load_state_dict(state_dict["model"]) | ||
|
||
# prediction | ||
data_dict = to_cuda(data_dict) | ||
output_dict = model(data_dict) | ||
data_dict = release_cuda(data_dict) | ||
output_dict = release_cuda(output_dict) | ||
|
||
# get results | ||
ref_points = output_dict["ref_points"] | ||
src_points = output_dict["src_points"] | ||
estimated_transform = output_dict["estimated_transform"] | ||
transform = data_dict["transform"] | ||
|
||
# visualization | ||
ref_pcd = make_open3d_point_cloud(ref_points) | ||
ref_pcd.estimate_normals() | ||
ref_pcd.paint_uniform_color(get_color("custom_yellow")) | ||
src_pcd = make_open3d_point_cloud(src_points) | ||
src_pcd.estimate_normals() | ||
src_pcd.paint_uniform_color(get_color("custom_blue")) | ||
draw_geometries(ref_pcd, src_pcd) | ||
src_pcd = src_pcd.transform(estimated_transform) | ||
draw_geometries(ref_pcd, src_pcd) | ||
|
||
# compute error | ||
rre, rte = compute_registration_error(transform, estimated_transform) | ||
print(f"RRE(deg): {rre:.3f}, RTE(m): {rte:.3f}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters