onnxruntime_flutter
onnxruntime_flutter copied to clipboard
How to detect object on the image with oxxnruntime_flutter using a pre-trained *.onnx model?
Please give an example how to inference image with pre-trained *.onnx
model using your package?
At the beginning I've trained YoloV8
model and got *.pt
trained model, then exported it to *.onnx
format with opset13
.
Inputs: [name: 'images', tensor: float32[1, 3, 320, 320]]
Outputs: [name: 'output0', tensor: float32[1, 6, 2100]]
[1, 6, 2100] in Outputs
- 6 means TWO objects to detect, 5 means ONE objects to detect
I've tried inference in Python with onnxruntime
package and it works great, but I can't get any results with your package. How to read/prepare image bytes to pass them as argument to createTensorWithDataList
method?
Here is my chunk of a code:
Int16List _transformBuffer(Uint8List bytes) => Int16List.view(bytes.buffer);
Future<void> inference() async {
final List<int> shape = [1, 3, 320, 320];
final floatBuffer = _transformBuffer(imageBytesList).map((e) => e / 255).toList();
array = Float32List.fromList(floatBuffer);
final OrtValueTensor inputOrt = OrtValueTensor.createTensorWithDataList(array, shape);
final Map<String, OrtValueTensor> inputs = {'images': inputOrt};
final runOptions = OrtRunOptions();
final List<OrtValue?>? outputs = await session.runAsync(runOptions, inputs, ['output0']);
}
Thank you in advance