exporting to onnx
See original GitHub issueI am trying to get this model (trained on custom dataset) to run under opencv so it will perform better on jetson nano. However, conversion to ONNX does not go well. this is the code i am using:
from effdet import get_efficientdet_config, EfficientDet
from effdet.bench import DetBenchPredict
from effdet.efficientdet import HeadNet
def load_net(checkpoint_path):
config = get_efficientdet_config('tf_efficientdet_d1')
net = EfficientDet(config, pretrained_backbone=False)
config.num_classes = 1
config.image_size=512
net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01))
checkpoint = torch.load(checkpoint_path)
net.load_state_dict(checkpoint['model_state_dict'])
net = DetBenchPredict(net, config)
net.eval();
return net.cuda()
import torch
from functools import partial
def load_model_weight(model, model_path):
model=torch.load(model_path)
model = model.eval()
return model
def export_onnx_model(model, input_shape, onnx_path, input_names=None, output_names=None, dynamic_axes=None):
inputs = torch.ones(*input_shape)
origin_forward = model.forward
model.forward = partial(
model.forward, img_scales=torch.tensor([1.0], dtype=torch.float).cuda(), img_size=torch.tensor([input_shape[-2:]], dtype=torch.float).cuda())
#model(inputs)
torch.onnx.export(model, (inputs), onnx_path, input_names=input_names, output_names=output_names, dynamic_axes=dynamic_axes)
model_path = "best-checkpoint-013epoch.bin"
model = load_net(model_path)
input_shape = (1, 3, 512, 512)
onnx_path = "test.onnx"
export_onnx_model(model, input_shape, onnx_path)
but it gives:
17 # Calculate asymmetric TensorFlow-like 'SAME' padding for a convolution
18 def get_same_padding(x: int, k: int, s: int, d: int):
---> 19 return max((math.ceil(x / s) - 1) * s + (k - 1) * d + 1 - x, 0)
20
21
RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future release div will perform true division as in Python 3. Use true_divide or floor_divide (// in Python) instead.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
(optional) Exporting a Model from PyTorch to ONNX and ...
To export a model, we call the torch.onnx.export() function. This will execute the model, recording a trace of what operators are used to...
Read more >Convert your PyTorch training model to ONNX
To export a model, you will use the torch.onnx.export() function. This function executes the model, and records a trace of what operators ...
Read more >Export to ONNX - Transformers
When a model is exported to the ONNX format, these operators are used to construct a computational graph (often called an intermediate representation)...
Read more >Best Practices for Neural Network Exports to ONNX
Exporting your model to ONNX helps you to decouple the (trained) model from the rest of your project. Moreover, exporting also avoids environment ......
Read more >Exporting your model to ONNX format | Barracuda
To use your trained neural network in Unity, you need to export it to the ONNX format. ONNX (Open Neural Network Exchange) is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mosheliv did you find a way to use the tf_efficientdet weights? I could export “efficientdet_dx” (without the padding) in onnx.
I didn’t need efficientdet specifically at this stage so switched to yolov4/yolov5. They have comparable performance and were ported to tensorrt (whichbwas why i started this unfortunate path). Good luck with trying, its not trivial…
On Wed, Dec 23, 2020, 18:43 Ekta P Bhojwani notifications@github.com wrote: