Comments (5)
All you have to do is break up the model before the final layer, Transpose
.
Read the README so thoroughly that it has holes in it.
https://github.com/PINTO0309/onnx2tf#2-run-test
# Split the model at the middle position for debugging
# Specify the output name of the OP
$ onnx2tf -i resnet18-v1-7.onnx -onimc resnetv15_stage2_conv1_fwd resnetv15_stage2_conv2_fwd
from onnx2tf.
Simply extrapolate Transpose to the back of the final layer.
https://github.com/PINTO0309/onnx2tf#parameter-replacement
https://github.com/PINTO0309/onnx2tf/tree/main/json_samples
from onnx2tf.
Hello, it seems like my previous response did not address my issue.
In the context of YOLOv8, the final output tensor shape is (1, 84, 8400) for my project. In YOLOv8-seg, the original output shape is (1, 116, 8400) and (1, 32, 160, 160).
The YOLOv8 official implementation also handles this special case in ultralytics/ultralytics/nn/autobackend.py, line 444.
# TF segment fixes: export is reversed vs ONNX export and protos are transposed
if len(y) == 2: # segment with (det, proto) output order reversed
if len(y[1].shape) != 4:
y = list(reversed(y)) # should be y = (1, 116, 8400), (1, 160, 160, 32)
y[1] = np.transpose(y[1], (0, 3, 1, 2)) # should be y = (1, 116, 8400), (1, 32, 160, 160)
y = [x if isinstance(x, np.ndarray) else x.numpy() for x in y]
In the model_zoo tflite provided by me, the shapes are (1, 116, 8400) and (1, 160, 160, 32), but in ONNX, it's (1, 116, 8400) and (1, 32, 160, 160). This means that the mask part is automatically transposed during conversion.
I am wondering if it's possible to add a transpose operation just before the last layer to handle this special case. When deploying, I want to output the original shapes (1, 116, 8400) and (1, 32, 160, 160) for efficiency. I have ten outputs for reg, cls, ms, and seg, respectively:
(1, 80, 80, 80) (1, 80, 40, 40) (1, 80, 20, 20)
(1, 1, 4, 6400) (1, 1, 4, 1600) (1, 1, 4, 400)
(1, 32, 80, 80) (1, 32, 40, 40) (1, 32, 20, 20)
(1, 32, 160, 160)
However, after converting to TFLite, the shapes become:
(1, 80, 80, 80) (1, 40, 40, 80) (1, 20, 20, 80)
(1, 6400, 4, 1) (1, 1600, 4, 1) (1, 400, 4, 1)
(1, 80, 80, 32) (1, 40, 40, 32) (1, 20, 20, 32)
(1, 160, 160, 32)
from onnx2tf.
Hello, I have already attempted to extrapolate the Transpose operation to the back of the final layer.
However I encountered some problems, and the output of the onnx model compared to the TFLite output doesn't seem to indicate that the operation was successful.
I think the reg3 in onnx and Identity_4296 in tflite is the same output.
but i still got (1,1,4,400) and (1,4,400,1)
I suspect there might be an issue with how I wrote my JSON file. The JSON file I used is shown below.
{
"format_version": 1,
"operations": [
{
"op_name": "reg1",
"param_target": "outputs",
"param_name": "reg1",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "cls1",
"param_target": "outputs",
"param_name": "cls1",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "reg2",
"param_target": "outputs",
"param_name": "reg2",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "cls2",
"param_target": "outputs",
"param_name": "cls2",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "reg3",
"param_target": "outputs",
"param_name": "reg3",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "cls3",
"param_target": "outputs",
"param_name": "cls3",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "mc1",
"param_target": "outputs",
"param_name": "mc1",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "mc2",
"param_target": "outputs",
"param_name": "mc2",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "mc3",
"param_target": "outputs",
"param_name": "mc3",
"post_process_transpose_perm": [0, 3, 2, 1]
},
{
"op_name": "seg",
"param_target": "outputs",
"param_name": "seg",
"post_process_transpose_perm": [0, 3, 2, 1]
}
]
}
Can you help me confirm what adjustments are needed? Thank you.
from onnx2tf.
I attempted to add a transpose layer at the end of an ONNX model, but after the conversion, that layer was directly removed.
from onnx2tf.
Related Issues (20)
- Trilu dtype error when using k greater than tensor dimension. HOT 1
- Onnx in tflite on Windows11 HOT 2
- (1)Not correctly recognize depthwise_conv (2)-oiqt could not skip SavedModel HOT 2
- Failed to convert model from segmentation_models_pytorch with dynamic shape HOT 2
- Improved grid_sample HOT 1
- onnx2tf `download_test_image_data()` S3 file connection error HOT 3
- Downgrade of ~10% on multiple weights of YoloX HOT 7
- I convert onnx to tensorflow use -osd option, saved_model wierd, almost every layer have many output HOT 2
- [ssdlite320_mobilenet_v3_large] Wrong shapes during inference HOT 2
- SavedModel saved prior to TF 2.5 detected when loading Keras model. HOT 2
- Conversion of ScatterND operator results in error HOT 2
- module 'tensorflow' has no attribute 'random' for tensorflow 2.15, but 2.14.0 does HOT 2
- Conversion of YoloV5, conversion of StridedSlice from 5d to 4d HOT 7
- Failed to convert Real-ESRGAN x4-general (NCHW) HOT 1
- Error when onnx2tf: Floating point exception (core dumped) HOT 10
- Full int8 quantized model doesn't work when "flatc" is installed on the system HOT 8
- ValueError: Exception encountered when calling layer "tf.math.multiply_46" (type TFOpLambda).
- 0 trainable parameters HOT 1
- Facing onnx2tf converstion issue with resnet model mentioned in README HOT 1
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 onnx2tf.