yalue / onnxruntime_go

A Go (golang) library wrapping microsoft/onnxruntime.
MIT License
187 stars 34 forks source link

Added option to allocate an output tensor #24

Closed YohayAiTe closed 1 year ago

YohayAiTe commented 1 year ago

I added an option to pass a null tensor to DynamicAdvancedSession.Run(), which will allocate the tensor and populate the slice with the new tensor. This is similar to the behaviour of the C/C++ API, and can be useful when the output shape can't be predicted at ahead of time (such as image object detection). Example usage:

session, _ := ort.NewDynamicAdvancedSession(/* parameters */)
outputs := []ort.ArbitraryTensor{nil, nil}
_ = session.Run(inputs, outputs)
confidence := outputs[0].(*ort.Tensor[float32])
defer confidence.Destroy()
bbox := outputs[1].(*ort.Tensor[float32])
defer bbox.Destroy()
yalue commented 1 year ago

Looks really cool! Apart from the one minor comment, would you mind adding a unit test for the new behavior to onnxruntime_test.go? I'll be happy to merge it after that. I may use some of what you added to implement the features requested in #22 (even though the requester no longer seems interested in that one).

YohayAiTe commented 1 year ago

I added a test and fixed the doc comment.

yalue commented 1 year ago

Looks great, thank you for working on it!

yalue commented 1 year ago

Realized I had forgotten to tag this. This feature is now included in tagged version v1.4.0