-
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
[java] Allows the creation and extraction of zero length tensors #15116
Conversation
@yuslepukhin would you mind taking a look at this? It fixes a behaviour difference between Java & Python which people run into when deploying object recognition systems that don't find any objects in the supplied image. |
I think you mean scalar tensors. They are not zero length. They do have empty shapes, however, the length is 1. Correct me if I am wrong. |
No, those are already supported in the Java API. This specifically deals with the case where a tensor is used with a variable dimension that happens to be zero. For example if the output shape is |
/azp run MacOS CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, ONNX Runtime Web CI Pipeline, onnxruntime-python-checks-ci-pipeline |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline |
Azure Pipelines successfully started running 5 pipeline(s). |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run orttraining-amd-gpu-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed, onnxruntime-binary-size-checks-ci-pipeline |
Azure Pipelines successfully started running 5 pipeline(s). |
/azp run Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ship
Description
Allows the creation of zero length tensors via the buffer path (the array path with zero length arrays still throws as the validation logic to check it's not ragged would require more intrusive revision), and allows the
tensor.getValue()
method to return a Java multidimensional array with a zero dimension. Also added a test for the creation and extraction behaviour.Motivation and Context
The Python interface can return zero length tensors (e.g. if object detection doesn't find any objects), and before this PR in Java calling
tensor.getValue()
throws an exception with a confusing error message. Fixes #7270 & #15107.