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

[C++] How to predict fast? #2118

Closed
bitnick10 opened this issue Oct 13, 2019 · 3 comments
Closed

[C++] How to predict fast? #2118

bitnick10 opened this issue Oct 13, 2019 · 3 comments

Comments

@bitnick10
Copy link

bitnick10 commented Oct 13, 2019

for (int i = 0; i < 1000*1000*1000; i++) {
    auto &input_tensor = input_tensor_vec[i];
    auto output_tensors = session_->Run(Ort::RunOptions{ nullptr }, input_node_names.data(), &input_tensor, 1, output_node_names.data(), 1);
}

This is really slow,is there some method make this faster (using C++)?

@hariharans29
Copy link
Member

Your model must support "batching" inherently and then you can feed in a "batched" input.

For example, if your model has graph input (taking image case) of shape [1, 3, 224, 224] - it can only take one 3 channel image of height and width 224. But if it has graph input like this - ["some_string", 3, 224, 224] - it can handle "batched" input of any size.

Hope this helps.

@bitnick10
Copy link
Author

import onnx
mp = onnx.load_model('aa.onnx')
mp.graph.input[0].type.tensor_type.shape.dim[0].dim_param = 'None'
onnx.save(mp, 'aa_batch.onnx')

[C++] after session_ load aa_batch.onnx.
auto output_tensors = session_->Run(Ort::RunOptions{ nullptr }, input_node_names.data(), &input_tensor, 1, output_node_names.data(), 1);
It runs very fast! Thanks @hariharans29

@cena001plus
Copy link

import onnx
mp = onnx.load_model('aa.onnx')
mp.graph.input[0].type.tensor_type.shape.dim[0].dim_param = 'None'
onnx.save(mp, 'aa_batch.onnx')

[C++] after session_ load aa_batch.onnx. auto output_tensors = session_->Run(Ort::RunOptions{ nullptr }, input_node_names.data(), &input_tensor, 1, output_node_names.data(), 1); It runs very fast! Thanks @hariharans29

Can it also speed up by simply modifying the model to dynamic input, without modifying the output node, and not batching the input data? Hope to hear from you.

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

3 participants