getImagePredictionFromBytesList method
Returns the predicted label for an image as a bytes list..
The image are passed as a list of Uint8List objects.
The imageWidth
and imageHeight
parameters specify the dimensions of the image.
The optional mean
and std
parameters can be used to normalize the image.
Returns a Future that resolves to a String representing the predicted label.
Implementation
Future<String> getImagePredictionFromBytesList(
List<Uint8List> imageAsBytesList, int imageWidth, int imageHeight,
{List<double> mean = torchVisionNormMeanRGB,
List<double> std = torchVisionNormSTDRGB}) async {
// Get the predictions using the getImagePredictionListFromBytesList method
final List<double> prediction = await getImagePredictionListFromBytesList(
imageAsBytesList, imageWidth, imageHeight,
mean: mean, std: std);
// Find the index of the prediction with the maximum score
int maxScoreIndex = softMax(prediction);
// Return the label corresponding to the maximum score
return labels[maxScoreIndex];
}