custom static method

TensorPipeline custom({
  1. required int height,
  2. required int width,
  3. InterpolationMode interpolation = InterpolationMode.bilinear,
  4. List<double>? mean,
  5. List<double>? std,
  6. bool addBatchDim = true,
  7. bool toChw = true,
})

Creates a fully customizable preprocessing pipeline.

Implementation

static TensorPipeline custom({
  required int height,
  required int width,
  InterpolationMode interpolation = InterpolationMode.bilinear,
  List<double>? mean,
  List<double>? std,
  bool addBatchDim = true,
  bool toChw = true,
}) {
  final ops = <dynamic>[
    ResizeOp(height: height, width: width, mode: interpolation),
  ];

  if (toChw) {
    ops.add(ToTensorOp(normalize: true));
  } else {
    ops.add(TypeCastOp.toFloat32());
    ops.add(ScaleOp.toUnit());
  }

  if (mean != null && std != null) {
    ops.add(NormalizeOp(mean: mean, std: std));
  }

  if (addBatchDim) {
    ops.add(UnsqueezeOp.batch());
  }

  return TensorPipeline(ops.cast(), name: 'Custom');
}