private async void LoadModel() { //Load a machine learning model StorageFile modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/MNIST.onnx")); ModelGen = await MNISTModel.CreateMNISTModel(modelFile); }
public MNISTModelVM() { model = new MNISTModel(); model.ResultIsReady += ResultEventHandler; ImageResults = new ObservableCollection <MNISTModelResult>(); ImageClasses = new ObservableCollection <ObservableCollection <MNISTModelResult> >(); ClassesInfo = new ObservableCollection <string>(); for (int i = 0; i < MNISTModel.NumOfClasses; i++) { ImageClasses.Add(new ObservableCollection <MNISTModelResult>()); ClassesInfo.Add(ClassInfoProcess(i, 0)); } Source = new CancellationTokenSource(); }
static async Task Main(string[] args) { MNISTModel model = new MNISTModel(); Console.CancelKeyPress += new ConsoleCancelEventHandler(CancelEventHandler); model.ResultIsReady += ResultEventHandler; try { // Console.Write("Choose directories with images: "); string dirPath = @"..\MNISTModelLib\Samples\Decoded"; //Console.ReadLine(); await model.PredImages(dirPath, source.Token); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void Evaluate_Click(object sender, EventArgs e) { // preprocess bitmap var preprocessed = new BitmapPreprocessor(bmp).PreprocessImage(); var bitmap = new BitmapData(preprocessed); // convert bitmap to dataset var data = new HandwrittenDigit { PixelData = bitmap.ToFloatArray() }; // train model (load from file if model exists) MNISTModel model = new MNISTModel(); model.Train(); // create PredictionEngine PredictionWrapper <HandwrittenDigit, HandwrittenDigitPrediction> wrapper = new PredictionWrapper <HandwrittenDigit, HandwrittenDigitPrediction>(model.Context, model.Transformer); wrapper.InitPredictionEngine(); // prediction result HandwrittenDigitPrediction prediction; wrapper.Predict(data, out prediction); // find highest confidence // find max score and retrieve number int max = 0; float maxScore = prediction.Score[0]; // iterate through all scoresto find max for (int i = 1; i < 10; i++) { // update max under correct condition if (prediction.Score[i] > maxScore) { max = i; maxScore = prediction.Score[i]; } } // update output label PredictionLabel.Text = max.ToString(); }
public ImageClassifier() { model = new MNISTModel(@"..\\..\\MNISTModelLib\\mnist-8.onnx"); }