Hello i am trying to make the "is this a hot dog" app from silicon valley using ML.net image classification.
I am working in a Maui app and already got a trained model which i put the zipfile in the app and the model.consumption file.
I already got code for taking a picture.
private async void OnTakePhotoClicked(object sender, EventArgs e)
{
var options = new StoreCameraMediaOptions();
var result = await CrossMedia.Current.TakePhotoAsync(options);
if (result is null) return;
UploadedOrSelectedImage.Source = ImageSource.FromStream(() => result.GetStream());
using var stream = result.GetStream();
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
var imageBytes = memoryStream.ToArray();
var modelInput = new MLModel2.ModelInput()
{
Label = "Image",
ImageSource = imageBytes
};
var prediction = MLModel2.Predict(modelInput);
ResultLabel.Text = prediction.PredictedLabel;
}
But it seems to always break when trying to find the zip file and trying to load the model.
private static async Task<PredictionEngine<ModelInput, ModelOutput>> CreatePredictEngine()
{
const string filePath = "MLModel2.zip";
using var stream = await FileSystem.OpenAppPackageFileAsync(filePath);
var mlContext = new MLContext();
ITransformer mlModel = mlContext.Model.Load(stream, out var _);
return mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
}
i already tried different file paths, but none seems to work.