-
Notifications
You must be signed in to change notification settings - Fork 3k
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
How to use batchsize in onnxruntime? #5577
Comments
"I think the sample means that the session itself do not care the shape of the input, just set the input_tensor the proper shape with the batchsize," - That is true but your model should also support it. In this case, your model does not - it is not flexible in its requirement - it expects batch size to be 1 and you provided 4. Usually the model input has a "dynamic" shape for the batch dimension (see #2118 #1944). I think some frameworks (Torch for example) support exporting the model with "dynamic" input shape requirements that can be used for batched inferencing. |
- use onnxruntime to run all models - implement dumping intermediate results - implement batch inference. Apparently onnxruntime does not support it directly if the ONNX model is not exported with a dynamic batch size [1]. I rewrite the model to work-around it. - Split out model configs so that it can be used in both transform.py and original_model_run.py Other changes: implement start for load_data_mnist() [1] microsoft/onnxruntime#5577
* Add an external MAML implementation as a submodule * Load omniglot * Model rewriting in transform.py - Change inputs for KWS to eliminate unsupported operators from the final ONNX model. - Save models at each step of rewriting for debugging - Inference dynamic shapes to get rid of a complex graph from forward steps like `x = x.view(x.size(0), -1)` - Constant folding for Squeeze and Reshape nodes with known new shape and constant input - Reduce global variables so that the latest model is always used after model rewriting * Other changes in transform.py - Move more ONNX helpers to utils.py - Make transformation of input samples more robust in terms of input shape - Don't use a default batch size; make that argument required. * Implement BatchNormalization * Use libc_nano instead of libc as the model omniglot-maml is too large [1] onnx/optimizer#38 [2] microsoft/onnxruntime#5577
* Add an external MAML implementation as a submodule * Load omniglot * Model rewriting in transform.py - Change inputs for KWS to eliminate unsupported operators from the final ONNX model. - Save models at each step of rewriting for debugging - Inference dynamic shapes to get rid of a complex graph from forward steps like `x = x.view(x.size(0), -1)` - Constant folding for Squeeze and Reshape nodes with known new shape and constant input - Reduce global variables so that the latest model is always used after model rewriting * Other changes in transform.py - Move more ONNX helpers to utils.py - Make transformation of input samples more robust in terms of input shape - Don't use a default batch size; make that argument required. * Implement BatchNormalization * Use libc_nano instead of libc as the model omniglot-maml is too large [1] onnx/optimizer#38 [2] microsoft/onnxruntime#5577
Describe the bug
I read the sample of imagenet and the Q&A(#1632), but I still do not know how to use batchsize.
I think the sample means that the session itself do not care the shape of the input, just set the input_tensor the proper shape with the batchsize, and run the session, like the code below:
auto output_tensors = session.Run(Ort::RunOptions{nullptr}, input_node_names.data(), &input_tensor, 1, output_node_names.data(), 2);
But, it doesn't work for me in the current version. It gives me some errors like:
terminate called after throwing an instance of 'Ort::Exception'
what(): Got invalid dimensions for input: data for the following indices
index: 0 Got: 4 Expected: 1
Please fix either the inputs or the model.
I deleted the check code and re-make the whole project.
But it still doesn't work. In output tensor, it just gives me random result except the first data in a batchsize.
System information
The text was updated successfully, but these errors were encountered: