getImagePredictionList method

Future<List<double>> getImagePredictionList(
  1. Uint8List imageAsBytes, {
  2. List<double> mean = torchVisionNormMeanRGB,
  3. List<double> std = torchVisionNormSTDRGB,
  4. PreProcessingMethod preProcessingMethod = PreProcessingMethod.imageLib,
})

Returns the predicted image as a list of scores using the given imageAsBytes.

The mean and std parameters are optional and default to the values of torchVisionNormMeanRGB and torchVisionNormSTDRGB. The preProcessingMethod parameter is optional and defaults to PreProcessingMethod.imageLib. Returns a Future that completes with a List<double> representing the predicted scores.

Implementation

Future<List<double>> getImagePredictionList(Uint8List imageAsBytes,
    {List<double> mean = torchVisionNormMeanRGB,
    List<double> std = torchVisionNormSTDRGB,
    PreProcessingMethod preProcessingMethod =
        PreProcessingMethod.imageLib}) async {
  // Assert mean std
  assert(mean.length == 3, "Mean should have size of 3");
  assert(std.length == 3, "STD should have size of 3");

  if (preProcessingMethod == PreProcessingMethod.imageLib) {
    Uint8List data = await ImageUtilsIsolate.convertImageBytesToFloatBuffer(
        imageAsBytes, imageWidth, imageHeight, mean, std);
    return (await ModelApi().getRawImagePredictionList(_index, data))
        .whereNotNull()
        .toList();
  }
  return (await ModelApi().getImagePredictionList(
          _index, imageAsBytes, null, null, null, mean, std))
      .whereNotNull()
      .toList();
}