createFixedSize static method
Creates a TensorBuffer with specified shape
and TfLiteType
. Here are some
examples:
Creating a float TensorBuffer with shape [2, 3]:
List<int> shape = [2, 3];
TensorBuffer tensorBuffer = TensorBuffer.createFixedSize(shape, TfLiteType.float32);
Creating an uint8 TensorBuffer of a scalar:
List<int> shape = [2, 3];
TensorBuffer tensorBuffer = TensorBuffer.createFixedSize(shape, TfLiteType.uint8);
Creating an empty uint8 TensorBuffer:
List<int> shape = [0];
TensorBuffer tensorBuffer = TensorBuffer.createFixedSize(shape, TfLiteType.uint8);
The size of a fixed-size TensorBuffer cannot be changed once it is created.
Throws ArgumentError.notNull if shape
is null and
ArgumentError is shape
has non-positive elements.
Implementation
static TensorBuffer createFixedSize(List<int> shape, TfLiteType dataType) {
switch (dataType) {
case TfLiteType.float32:
return TensorBufferFloat(shape);
case TfLiteType.uint8:
return TensorBufferUint8(shape);
default:
throw ArgumentError(
'TensorBuffer does not support data type: \" +$dataType');
}
}