onnxruntime/samples/swift
Thiago Crepaldi 83be3759bc
Add post-install command to build PyTorch CPP extensions from within onnxruntime package (#8027)
ORTModule requires two PyTorch CPP extensions that are currently JIT compiled. The runtime compilation can cause issues in some environments without all build requirements or in environments with multiple instances of ORTModule running in parallel

This PR creates a custom command to compile such extensions that must be manually executed before ORTModule is executed for the first time. When users try to use ORTModule before the extensions are compiled, an error with instructions are raised

PyTorch CPP Extensions for ORTModule can be compiled by running:
python -m onnxruntime.training.ortmodule.torch_cpp_extensions.install

Full build environment is needed for this
2021-06-28 18:11:58 -07:00
..
SwiftMnist Add post-install command to build PyTorch CPP extensions from within onnxruntime package (#8027) 2021-06-28 18:11:58 -07:00
SwiftMnist.xcodeproj
ReadMe.md

MNIST Sample - Number recognition

This sample uses the MNIST model from the Model Zoo: https://github.com/onnx/models/tree/master/vision/classification/mnist

Screenshot

Requirements

  • MacOS Catalina
  • Xcode 11
  • Compiled libonnxruntime.dll / lib

Build

Command line:

$ xcodebuild -project SwiftMnist.xcodeproj 

From Xcode, open SwiftMnist.xcodeproj and run with Command-R.

How to use it

Just draw a number on the surface, when you lift your finger from the mouse or the trackpad, the guess will be displayed.

Note that when drawing numbers requiring multiple drawing strokes, the model will be run at the end of each stroke with probably wrong predictions (but it's amusing to see and avoids needing to press a 'run model' button).

How it works

(Add once it is added)

Preprocessing the data

MNIST's input is a {1,1,28,28} shaped float tensor, which is basically a 28x28 floating point grayscale image (0.0 = background, 1.0 = foreground).

Postprocessing the output

MNIST's output is a simple {1,10} float tensor that holds the likelihood weights per number. The number with the highest value is the model's best guess.

The MNIST structure uses std::max_element to do this and stores it in result_:

521dc75798/samples/c_cxx/MNIST/MNIST.cpp (L31)