import torch
import torchvision.models as models
torch_model = torch.load("faster_rcnn.pth")
model = models.resnet50()
model.fc = torch.nn.Linear(2048, 4)
model.load_state_dict(torch_model,False)
batch_size = 1
input_shape = (3, 244, 384)
model.eval()
x = torch.randn(batch_size, *input_shape)
export_onnx_file = "test.onnx"
torch.onnx.export(model,
x,
export_onnx_file,
opset_version=10,
do_constant_folding=True,
input_names=["input"],
output_names=["output"],
dynamic_axes={"input":{0:"batch_size"},
"output":{0:"batch_size"}})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26