Hi everyone!
I have trained pytorch SSD512 model on custom dataset using pre-trained VGG16 as featurizer. Now I want to convert it to ONNX format to be able to make predictions using ML.NET. Model is converted without errors, nevertheless it doesn’t pass onnx.checker.check_model.
I use macOS 10.13.6, pytorch 1.1.0, onnx 1.5.0
My model was trained on GPU server.
Here is my code to convert:
from ssd.config import cfg
from ssd.modeling.detector import build_detection_model
import torch
from torch import nn
if __name__ == '__main__':
cfg.merge_from_file('configs/vgg_ssd512.yaml')
model = build_detection_model(cfg)
state_dict = torch.load('model_final.pth', map_location=lambda storage, loc: storage)['model']
model.load_state_dict(state_dict)
dummy_input = torch.randn(1, 3, 512, 512, device='cpu')
torch.onnx.export(model, dummy_input, 'ssdpytorch.onnx', opset_version=10, input_names=['image'], output_names=['scores', 'boxes'], verbose=True)
And the following error occurs:
ValidationError Traceback (most recent call last)
<ipython-input-30-b6beadd98bdc> in <module>()
----> 1 onnx.checker.check_model(model)
//anaconda/lib/python3.6/site-packages/onnx/checker.py in check_model(model)
84 C.check_model_path(model)
85 else:
---> 86 C.check_model(model.SerializeToString())
87
88
ValidationError: Node () has input size 1 not in range [min=3, max=5].
==> Context: Bad node spec: input: "306" output: "308" op_type: "Slice" attribute { name: "axes" ints: 2 type: INTS } attribute { name: "ends" ints: 2 type: INTS } attribute { name: "starts" ints: 0 type: INTS }
Here is onnx model: https://gofile.io/?c=wGr587