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

Change dynamic shape in fixed shape using C++ #6118

Closed
LaurentBerger opened this issue May 1, 2024 · 1 comment
Closed

Change dynamic shape in fixed shape using C++ #6118

LaurentBerger opened this issue May 1, 2024 · 1 comment
Labels
question Questions about ONNX

Comments

@LaurentBerger
Copy link

I want to change dynamic shape in a fixed shape in C++

Question

How to do it in C++?

Further information

First i try to change input size :

        std::map<std::string, int> valSubstitute;
        val["w"] = 640;
        val["h"] = 480;


            for (int i = 0; i < graph_proto->input_size(); i++)
            {
                auto node = graph_proto->input(i);
                for (int j = 0; j < node.type().tensor_type().shape().dim_size(); j++)
                {
                    auto dimx = node.type().tensor_type().shape().dim()[j];
                    if (dimx.has_dim_param())
                    {
                        if (valSubstitute.find(dimx.dim_param()) != valSubstitute.end())
                        {
                            std::string key(dimx.dim_param());
                            dimx.clear_dim_param();
                            dimx.set_dim_value(valSubstitute[key]);
                        }
                    }
                    else
                        std::cout << "dim " << dimx.dim_value() << "\n";
                }
            }

then I scan my change

            std::cout << "Scan 2 : graph_proto->input_size \n";
            for (int i = 0; i < graph_proto->input_size(); i++)
            {
                auto node = graph_proto->input(i);
                for (int j = 0; j < node.type().tensor_type().shape().dim_size(); j++)
                {
                    auto dimx = node.type().tensor_type().shape().dim()[j];
                    if (dimx.has_dim_param())
                    {
                        std::cout << "dim " << dimx.dim_param() << "\n";
                        if (valSubstitute.find(dimx.dim_param()) != valSubstitute.end())
                            dimx.set_dim_value(valSubstitute[dimx.dim_param()]);
                        if (dimx.has_dim_param())
                            std::cout << "No !dim " << dimx.dim_param() << "\n";
                    }
                    else
                        std::cout << "dim " << dimx.dim_value() << "\n";
                }
            }

result is : no change in scan 2

Scan 1 : graph_proto->input_size
dim 1
dim 3
dim 480
dim 640
Scan 2 : graph_proto->input_size
dim 1
dim 3
dim h
dim w

  • Is this issue related to a specific model?
    No but i work on dexined model

Notes

I'm not an expert in Onnx

@LaurentBerger LaurentBerger added the question Questions about ONNX label May 1, 2024
@LaurentBerger
Copy link
Author

LaurentBerger commented May 2, 2024

solved : clone ModelProto and change data

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

No branches or pull requests

1 participant