Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m trying to export from pth to ONNX format:

import torch
from torch.autograd import Variable
import cv2
import imgproc
from craft import CRAFT

# load net
net = CRAFT()     # initialize
net = net.cuda()
net = torch.nn.DataParallel(net)


# load data
image = imgproc.loadImage('./misc/test.jpg')

# resize
img_resized, target_ratio, size_heatmap = imgproc.resize_aspect_ratio(image, 1280, interpolation=cv2.INTER_LINEAR, mag_ratio=1.5)
ratio_h = ratio_w = 1 / target_ratio

# preprocessing
x = imgproc.normalizeMeanVariance(img_resized)
x = torch.from_numpy(x).permute(2, 0, 1)    # [h, w, c] to [c, h, w]
x = Variable(x.unsqueeze(0))                # [c, h, w] to [b, c, h, w]
x = x.cuda()

# trace export

But then encountered this error:

RuntimeError: tuple appears in op that does not forward tuples (VisitNode at /opt/conda/conda-bld/pytorch_1556653114079/work/torch/csrc/jit/passes/lower_tuples.cpp:117)

Followed these issue and, it turnned out that nn.DataParallel wrapper doesn’t support trace export for ONNX.

Is there a workaround for this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:19

github_iconTop GitHub Comments

ajinkya933commented, Sep 23, 2019

I have exported this graph to onnx and Ive added the details on how to do it in my fork here:

Hope it helps.

If anyone knows how to take inference from it pl tell me

piernikowyludekcommented, Sep 18, 2019

@hiepph Hi, if you still haven’t managed to convert the model to ONNX you may find this thread helpful: I converted the model successfully to .onnx now. It is very much an onnx library problem.

I do get stuck at the next step though - converting the .onnx to .pb file ;D So if anyone crosses that bridge, I will appreciate your help!

Read more comments on GitHub >

github_iconTop 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 - Microsoft Learn
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 - Hugging Face
In this guide, we'll show you how to export Transformers models to ONNX (Open Neural Network eXchange). Once exported, a model can be...
Read more >
How to Convert a PyTorch Model to ONNX in 5 Minutes - Deci AI
The next step is to use the `torch.onnx.export` function to convert the model to ONNX. This function requires the following data:.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found