lhwcv / mlsd_pytorch

Pytorch implementation of "M-LSD: Towards Light-weight and Real-time Line Segment Detection"
Apache License 2.0
189 stars 37 forks source link

How to convert the model to onnx format? #8

Open magicChos opened 2 years ago

magicChos commented 2 years ago

my conversion seems wrong.

thanks very much!

SuperChay commented 2 years ago
convert the model to onnx ```java import torch from models.mbv2_mlsd_large import MobileV2_MLSD_Large def pth2onnx(): model_path = '../models/mlsd_large_512_fp32.pth' model = MobileV2_MLSD_Large().cuda().eval() device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model.load_state_dict(torch.load(model_path, map_location=device), strict=True) dummy_input = torch.randn(1, 4, 512, 512, device=device) torch.onnx.export(model, dummy_input, "../models/test.onnx", verbose=True, opset_version=11) if __name__ == '__main__': pth2onnx() ```