partial void TappedClear(UIButton sender) { // clear the digitview DigitView.Lines.Clear(); DigitView.SetNeedsDisplay(); PredictionLabel.Hidden = true; }
partial void TappedDetectDigit(UIButton sender) { // get the digitView context so we can get the pixel values from it to intput to network var context = DigitView.GetViewContext(); // validate NeuralNetwork was initialized properly if (runningNet == null) { throw new InvalidProgramException(); } // putting input into MTLTexture in the MPSImage var region = new MTLRegion(new MTLOrigin(0, 0, 0), new MTLSize((nint)mnistInputWidth, mnistInputHeight, 1)); runningNet.SrcImage.Texture.ReplaceRegion(region, level: 0, slice: 0, pixelBytes: context.Data, bytesPerRow: mnistInputWidth, bytesPerImage: 0); // run the network forward pass var label = runningNet.Forward(); // show the prediction PredictionLabel.Text = $"{label}"; PredictionLabel.Hidden = false; }
void ReleaseDesignerOutlets() { if (AccuracyLabel != null) { AccuracyLabel.Dispose(); AccuracyLabel = null; } if (DigitView != null) { DigitView.Dispose(); DigitView = null; } if (PredictionLabel != null) { PredictionLabel.Dispose(); PredictionLabel = null; } }