Trains a handwritten digit classifier using the Torch C backend. Like other Torch clients, most prominently PyTorch, this example is built on top of the ATen C API, showing how a Torch client for Kotlin/Native could look like.
To build ATen (Torch for C), make sure you have Python 2.X and pyyaml installed:
# macOS: if you don't have pip sudo easy_install pip # Linux: if you don't have pip apt-get -y install python-pip # if you don't have pyyaml or typing sudo pip install pyyaml typing
will install it into
$HOME/.konan/third-party/torch (if not yet done). One may override the location of
third-party/torch by setting the
KONAN_DATA_DIR environment variable.
To build use
Alternatively you can run the artifact directly through
You may need to specify
DYLD_LIBRARY_PATH environment variables
to point to
$HOME/.konan/third-party/torch/lib if the ATen dynamic library cannot be found.
Even on a CPU, training should only take some minutes, and you should observe a classification accuracy of about 95% on the test dataset.