You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found that it is probably the same issue as #16781.
I am using ONNX to serve a scikit-learn trained model inside Java code. The output is returned as OnnxValue object and I apply getValue() to retrieve the output value. As per API documentation it is supposed to return the value as a Java object and I understand I should be able to extract the primitive value, such as float or array. At least for OnnxTensor the API doc says Either returns a boxed primitive if the Tensor is a scalar, or a multidimensional array of primitives if it has multiple dimensions. Logging the type, by applying getType() method, shows the correct type OnnxTensor(info=TensorInfo(javaType=INT64,onnxType=ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,shape=[1])). However, casting it into long, or int, throws exception and I do not see any other method or way to get the primitive or array. How would I extract the value from the java object?
To reproduce
Java version:
openjdk version "11.0.21" 2023-10-17
OpenJDK Runtime Environment (build 11.0.21+9-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.21+9-post-Ubuntu-0ubuntu122.04, mixed mode)
Cast it to long[] not long. You can always reflectively inspect the type of the object returned by getValue, e.g. results.get("output_label").get().getValue().getClass() will return long[].class. Scalars have shape [], whereas this model produces something of shape [batch_size] so while there is only a single element in this case, it's a 1d vector which we return as a 1d array.
Cast it to long[] not long. You can always reflectively inspect the type of the object returned by getValue, e.g. results.get("output_label").get().getValue().getClass() will return long[].class. Scalars have shape [], whereas this model produces something of shape [batch_size] so while there is only a single element in this case, it's a 1d vector which we return as a 1d array.
This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.
Describe the issue
I found that it is probably the same issue as #16781.
I am using ONNX to serve a scikit-learn trained model inside Java code. The output is returned as
OnnxValue
object and I apply getValue() to retrieve the output value. As per API documentation it is supposed to return the value as a Java object and I understand I should be able to extract the primitive value, such as float or array. At least forOnnxTensor
the API doc saysEither returns a boxed primitive if the Tensor is a scalar, or a multidimensional array of primitives if it has multiple dimensions.
Logging the type, by applying getType() method, shows the correct typeOnnxTensor(info=TensorInfo(javaType=INT64,onnxType=ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,shape=[1]))
. However, casting it into long, or int, throws exception and I do not see any other method or way to get the primitive or array. How would I extract the value from the java object?To reproduce
pip install skl2onnx
save the onnx packaged model
rf_iris.onnx
undersrc/main/resources
4. File
pom.xml
OnnxRf.java
Urgency
No response
Platform
Windows
OS Version
Ubuntu 22.04.3 LTS
ONNX Runtime Installation
Built from Source
ONNX Runtime Version or Commit ID
1.16.3
ONNX Runtime API
Python
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response
The text was updated successfully, but these errors were encountered: