createUint8Tensor method
You MUST call calloc.free on the returned pointer when you are done with
it, i.e. once inference is complete.
Implementation
Pointer<Uint8> createUint8Tensor(
Pointer<Pointer<OrtValue>> inputTensorPointer, {
required Pointer<OrtMemoryInfo> memoryInfo,
required List<int> values,
}) {
final sizeOfUint8 = sizeOf<Uint8>();
final inputTensorNative = calloc<Uint8>(values.length * sizeOfUint8);
for (var i = 0; i < values.length; i++) {
inputTensorNative[i] = values[i];
}
final inputShape = calloc<Int64>(2 * sizeOf<Int64>());
inputShape[0] = 1;
inputShape[1] = values.length;
final status = createTensorWithDataAsOrtValue(
inputTensorPointer,
memoryInfo: memoryInfo,
inputData: inputTensorNative.cast<Void>(),
inputDataLengthInBytes: values.length * sizeOfUint8,
inputShape: inputShape,
inputShapeLengthInBytes: 2,
onnxTensorElementDataType:
ONNXTensorElementDataType.ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8.value,
);
if (status.isError) {
final error =
'Code: ${getErrorCodeMessage(status)}\n'
'Message: ${consumeErrorMessage(status)}';
calloc.free(inputTensorNative);
calloc.free(inputShape);
throw Exception(error);
}
calloc.free(inputShape);
return inputTensorNative;
}