场景训练
Closed this issue · 4 comments
你好!,你在鱼眼场景进行训练嘛?我想要在图像尺寸128*128上进行训练,不知道效果怎么样
@longzeyilang 我没有训练,模型直接拿来用就行,我测试下来感觉效果比orb, sift要好很多,比superpoint也要好一些。
@meyiao 我将模型尺寸转化为128*128的
`import torch
from modules.xfeat import XFeatModel
import onnxruntime as ort
import onnx
import onnxsim
os.environ['CUDA_VISIBLE_DEVICES'] = '' #Force CPU, comment for GPU
set the model to evaluation mode
net = XFeatModel().eval()
load the pretrained weights
net.load_state_dict(torch.load("weights/xfeat.pt", map_location=torch.device('cpu')))
Random input
x = torch.randn(1, 1, 240, 320)
output_path = 'xfeat.onnx'
export to ONNX
torch.onnx.export(net, x, output_path, verbose=True,
input_names=['input'],
output_names=['output_feats', "output_keypoints", "output_heatmap"],
opset_version=11)
# Simplify model
onnx_model = onnx.load(output_path)
model_sim, check = onnxsim.simplify(onnx_model)
if check:
# output_path = output_path.replace(".onnx", "_sim.onnx")
onnx.save(model_sim, output_path)
print("Simplified ONNX model has been saved.")
print("ONNX model saved as xfeat.onnx")
check the onnx model with onnxruntime
ort_session = ort.InferenceSession("xfeat.onnx")
print("ONNX model loaded successfully")
outputs = ort_session.run(None, {"input": x.numpy()})
pytorch model outputs
torch_outputs = net(x)
compare the outputs
for i in range(len(outputs)):
print(f"onnx output shape {i}: {outputs[i].shape}")
print(f"torch output shape {i}: {torch_outputs[i].shape}")
print(f"Output {i} comparison: {torch.allclose(torch_outputs[i], torch.tensor(outputs[i]))}")
print(f'Output {i} max diff: {torch.max(torch.abs(torch_outputs[i] - torch.tensor(outputs[i])))}')
print("\n")
`
送进模型检测,实际配对点效果并不好,不知道原因在哪里
@longzeyilang 我QQ很久没用了,你可以把图像对发出来,我有空的时候就试下
@meyiao 我的qq邮箱: 1143059946@qq.com,你能发信给我嘛?我给你发些邮件