dart_tensor_preprocessing library

A high-performance tensor preprocessing library for Flutter/Dart.

This library provides NumPy-like tensor transforms optimized for ONNX Runtime inference. Key features include:

Getting Started

import 'package:dart_tensor_preprocessing/dart_tensor_preprocessing.dart';

// Create a preprocessing pipeline
final pipeline = TensorPipeline([
  ResizeOp(height: 224, width: 224),
  NormalizeOp.imagenet(),
  PermuteOp.hwcToChw(),
]);

// Run synchronously
final result = pipeline.run(inputTensor);

// Or run asynchronously in an isolate
final result = await pipeline.runAsync(inputTensor);

See PipelinePresets for pre-configured pipelines for common models.

Classes

AbsOp
Computes the absolute value of each element.
AddOp
Adds a scalar or tensor to the input element-wise.
ArithmeticOp
Base class for binary arithmetic operations.
BatchNormOp
Batch Normalization for inference.
BufferPool
A pool of reusable TypedData buffers for memory optimization.
CenterCropOp
Crops a tensor from the center to the specified dimensions.
ClipOp
Clips tensor values to a specified range.
ContiguousOp
Forces a tensor to be contiguous in memory.
DivOp
Divides the input by a scalar or tensor element-wise.
DTypeDispatcher
Utility for dispatching operations based on tensor dtype.
ExpOp
Computes the exponential (e^x) of each element.
FlattenOp
Flattens dimensions in a specified range into a single dimension.
GaussianBlurOp
Applies Gaussian blur to tensor for data augmentation.
IdentityOp
A no-op transform that returns the input unchanged.
LayerNormOp
Layer Normalization for inference.
LayoutConvertOp
Converts a tensor between memory layout formats (NCHW/NHWC).
LeakyReLUOp
Leaky Rectified Linear Unit activation function.
LogOp
Computes the natural logarithm of each element.
MulOp
Multiplies the input by a scalar or tensor element-wise.
NegOp
Negates each element.
NormalizeOp
Normalizes tensor values per channel using mean and standard deviation.
PadOp
Pads tensor with specified padding on spatial dimensions.
PermuteOp
Permutes the dimensions of a tensor according to dims.
PipelinePresets
Pre-configured preprocessing pipelines for common ML models.
PowOp
Raises each element to the given power.
RandomCropOp
Randomly crops tensor to specified dimensions for data augmentation.
ReLUOp
Rectified Linear Unit (ReLU) activation function.
ReshapeOp
Reshapes a tensor to the specified shape.
ResizeOp
Resizes a tensor to a fixed height and width.
ResizeShortestOp
Resizes a tensor so that the shortest edge matches shortestEdge.
ScaleOp
Scales tensor values by a constant factor.
SigmoidOp
Sigmoid activation function.
SliceOp
Slices tensor with Python-like syntax.
SoftmaxOp
Softmax activation function.
SqrtOp
Computes the square root of each element.
SqueezeOp
Removes size-1 dimensions from a tensor.
SubOp
Subtracts a scalar or tensor from the input element-wise.
TanhOp
Hyperbolic tangent (Tanh) activation function.
TensorBuffer
A multi-dimensional array view over typed data with shape and stride metadata.
TensorIndexer
Utilities for tensor index calculations.
TensorPipeline
A composable sequence of tensor transform operations.
TensorStorage
An immutable wrapper around typed data that provides the physical storage for TensorBuffer.
ToImageOp
Converts a tensor from CHW/NCHW to HWC/NHWC image format.
ToTensorOp
Converts an image tensor from HWC/NHWC to CHW/NCHW format.
TransformOp
Base class for all tensor transform operations.
TypeCastOp
Casts tensor element values to a different data type.
TypedDataViews
Utilities for working with TypedData views and zero-copy operations.
UnaryMathOp
Base class for unary math operations.
UnsqueezeOp
Inserts a size-1 dimension at the specified position.

Enums

DType
Represents the data type of tensor elements.
InterpolationMode
Interpolation algorithm used for image resizing.
MemoryFormat
Defines the memory layout format for tensor data.
PadMode
Padding modes for PadOp.

Mixins

InPlaceTransform
Mixin for transforms that can modify tensors in place.
RequiresContiguous
Mixin for transforms that require contiguous tensor input.

Extensions

BufferPoolExtension on BufferPool
Extension to add pool-aware operations to TensorBuffer.
MemoryFormatExtension on MemoryFormat
Extension providing utility methods for MemoryFormat.
TensorViewExtension on TensorBuffer
Extension methods for creating tensor views efficiently.

Functions

concat(List<TensorBuffer> tensors, {int axis = 0}) TensorBuffer
Concatenates multiple tensors along a specified axis.

Exceptions / Errors

DTypeMismatchException
Thrown when tensor data types do not match.
EmptyPipelineException
Thrown when attempting to create an empty pipeline.
IndexOutOfBoundsException
Thrown when an index or axis is out of valid range.
InvalidParameterException
Thrown when a transform operation receives an invalid parameter value.
NonContiguousException
Thrown when an operation requires a contiguous tensor but receives a non-contiguous one.
ShapeMismatchException
Thrown when tensor shapes do not match expected dimensions.
TensorException
Base class for all tensor-related exceptions.