Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onnx model successfully converted to synet but failed to load #40

Closed
theoractice opened this issue Aug 4, 2024 · 4 comments
Closed

Comments

@theoractice
Copy link

I tried to convert my model to synet format and it worked:

Convert network from Onnx to Synet : OK.

However when loading the model, net.Load("synet.xml", "synet.bin"); throws exception:

Assertion failed: startAxis <= endAxis && (size_t)endAxis <= _shape.size(), file D:\Coding\git\Synet\src\Synet\Tensor.h, line 396

Onnx model file if needed:
https://we.tl/t-DrVIgiWe7h

@ermig1979
Copy link
Owner

Hi! Excuse me for so late answer - I was at vacation. I try to reproduce this bug but this link is expired. Would you to sent me this model one more time?

@theoractice
Copy link
Author

Thanks for your kind reply. Model link updated:
https://we.tl/t-UumyOc8lop
BTW the model was converted under linux, but loaded under Win10 using Synet commit c995873.

@ermig1979
Copy link
Owner

If you convert this model for NCHW format:

./TestOnnx -m=convert -fw=./model.onnx -sm=./synet.xml -sw=./synet.bin -tf=0 

It will be work fine but it does not achiev the best performance.

There are troubles to convert Synet model in NHWC format. The converter to NHWC poor works with Reshape layers and other complicated logic. Fortunately the main computational load concerned with backbone computations which can be correct converted. The rest part may use NCHW format.
In some times the converter can insert Permute layers to convert from NHWC to NCHW by itself but some times it requires of user hints.
In your case you have to create file ./param.xml:
param.zip

./TestOnnx -m=convert -fw=./model.onnx -sm=./synet.xml -sw=./synet.bin -tf=1 -tp=./param.xml 

@theoractice
Copy link
Author

theoractice commented Aug 23, 2024

Thank you for your kind reply, it's very helpful. I tried your solution and my model now loads successfully.

This is my working Synet code snippet:

auto image = imread("image.png", IMREAD_GRAYSCALE);
Mat img;
resize(image, img, Size(48, 48));
img.convertTo(img, CV_32FC1, 1.0f / 127.5f, -1.0f);

float* input_tensor_data = net.Src()[0]->CpuData();
memcpy(input_tensor_data, img.data, img.total() * sizeof(float));
net.SetInput(inputView, -1.0f, 1.0f);
net.Forward();

const float* output_tensor_data = net.Dst()[0]->CpuData();

Now it works perfectly. Amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants