getImagePrediction method

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

Returns the predicted image label 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 String representing the predicted image label.

Implementation

Future<String> getImagePrediction(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");

  final List<double> prediction = await getImagePredictionList(imageAsBytes,
      mean: mean, std: std, preProcessingMethod: preProcessingMethod);

  int maxScoreIndex = softMax(prediction);
  return labels[maxScoreIndex];
}