Comments (7)
@zhiqwang @SharynHu is right.
instead of using
yolort/yolort/runtime/ort_helper.py
Line 236 in 672ae82
try to use tuple with an empty target None
with BytesIO() as f:
torch.onnx.export(
self.model,
(self.input_sample, None),
f,
do_constant_folding=True,
opset_version=self._opset_version,
input_names=self.input_names,
output_names=self.output_names,
dynamic_axes=self.dynamic_axes,
**kwargs,
)
from yolort.
I reproduced this problem on my ubuntu platform with torch2.0cu117. Everything seems fine till torch.onnx.export
runs the function _decide_input_format(model, args)
internally. This function will change the passedargs
parameter, appending a None
to its end. I think it intends to match the input,target
signature in the YOLO5:forward
method. Since target is not provided explicitly, it adds an None
to the input. However, when farwarding, that added None
is not interpreted as the second parameter target
but the second element of input
, which produces this bug.
from yolort.
Sorry for the delay in replying to you @mr-mainak , The whole workflow looks fine, the onnx we export now is too dynamic to be used by opencv.dnn
, and perhaps we should need to trade off some dynamics to guarantee better generalizability.
from yolort.
I got the exact same error, it will work with batch_size != 1
from yolort.
I got the exact same error, it will work with batch_size != 1
You are right. I just tried with batch_size != 1, it worked. But still wonder if the bug can be fixed later on.
from yolort.
Sorry @willjoy and @Wikidepia , I've missed this tickets, I can reproduce this problem locally. And seems that this is caused by the newer version of PyTorch (1.11-1.13), I only test this function at PyTorch 1.9-1.10, we need to fix this problem.
from yolort.
However while transforming such output is coming:
/home/mainak/ms/python/onnx_env/lib/python3.8/site-packages/yolort/models/transform.py:282: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).
img_h, img_w = _get_shape_onnx(img)
/home/mainak/ms/python/onnx_env/lib/python3.8/site-packages/yolort/models/anchor_utils.py:46: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
anchors = torch.as_tensor(self.anchor_grids, dtype=torch.float32, device=device).to(dtype=dtype)
/home/mainak/ms/python/onnx_env/lib/python3.8/site-packages/yolort/models/anchor_utils.py:47: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
strides = torch.as_tensor(self.strides, dtype=torch.float32, device=device).to(dtype=dtype)
/home/mainak/ms/python/onnx_env/lib/python3.8/site-packages/yolort/models/box_head.py:406: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
strides = torch.as_tensor(self.strides, dtype=torch.float32, device=device).to(dtype=dtype)
/home/mainak/ms/python/onnx_env/lib/python3.8/site-packages/yolort/models/box_head.py:337: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).
for head_output, grid, shift, stride in zip(head_outputs, grids, shifts, strides):
Is this normal? Then when I'm loading with opencv dnn readNetFromONNX
module the following error is coming:
[ERROR:[email protected]] global onnx_importer.cpp:2588 parseShape DNN/ONNX(Shape): dynamic 'zero' shapes are not supported, input image [ 3 0 0 ]
[ERROR:[email protected]] global onnx_importer.cpp:1061 handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [Shape]:(onnx_node!/Shape) from domain='ai.onnx'
I am having best.pt which is obtained from training(best mAP). In order to convert this weights I'm changing the path_ultralytics_yolov5
in helper.py
. Is this the correct way because when I open the onnx in Netron it's architecture is different.
from yolort.
Related Issues (20)
- `numpy` does not support newline delimiter from version 1.23
- zlibwapi.dll (solved)
- No module named 'yolort.utils.update_module_state' while saving the Yolo Model HOT 6
- Dynamic batch dimension not working with ONNX export HOT 1
- module 'yolort' has no attribute 'utils' HOT 4
- Can't load custom trained model HOT 2
- Unexpected side effect on matplotlib's backend HOT 2
- Remove `NestedTensor` from pre-processing
- Loading pre-trained model is not supported for num_classes != 80 HOT 1
- Can bbox coordinates be negative in yolo output? HOT 6
- Remove `ComputeLoss` from TorchScript graph
- SpeedUp with microsoft/nni HOT 3
- CLI tool for exporting models.: error: the following arguments are required: --checkpoint_path HOT 16
- Is it correct to subtract x_offset twice when performing bbox scale as post-processing? HOT 1
- If put yolov5 onnx exported from ultralytics into export_engine api, the postprocess speed slows down in cpp deploy. HOT 8
- SetCriterion's forward() incompatible with P6 models. Can't train P6 models.
- [defaultAllocator.cpp::deallocate::42] Error Code 1: Cuda Runtime (invalid argument) Segmentation fault (core dumped)
- Exporting ONNX Model with Fixed Batch Size of 1 Using export_tensorrt_engine
- cant batch infer?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yolort.