models icon indicating copy to clipboard operation
models copied to clipboard

Extracting the prediction Result from the OnnxTensor

Open anirudhsrikanth-cs opened this issue 3 years ago • 0 comments

Problem

How do I extract the prediction probability values from the result OnnxTensor after we use session.run() in Java?

Question

I am taking a string as in input from the Command Line. I already have a ML model saved in the onnx format and I'm only performing inference in Java. It is a Vectorizer + RandomForest pipeline.

I'm converting the string to a String[][] array and storing it as an onnxtensor. Next I'm putting the onnxtensor with the input column name in a HashMap<String, OnnxTensor>()

OrtSession.Result results = session.run(Collections.singletonMap(inputMeta.getName(), inputTensor))

The results is as follows:

OnnxTensor(info=TensorInfo(javaType=INT64,onnxType=ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64,shape=[1]))
OnnxSequence(info=SequenceInfo(length=1,type=MapInfo(size=2,keyType=INT64,valueType=FLOAT)))

How do I extract the prediction probabilities from this object ?

Also I'm not sure if I'm doing the whole thing right, so any suggestions would be really helpful.

Thanks

anirudhsrikanth-cs avatar Jul 26 '22 00:07 anirudhsrikanth-cs