The C++ native part of the project

We perform the main classification task in the native C++ library. The Android Studio IDE has already created the native-lib.cpp file for us, so we just have to modify it. The following code snippet shows what header files we should include in order to work with the JNI, PyTorch, and Android asset libraries:

#include <jni.h>#include <string>#include <iostream>#include <torch/script.h>#include <caffe2/serialize/read_adapter_interface.h>#include <android/asset_manager_jni.h>#include <android/asset_manager.h>

If you want to use the Android logging system to output some messages to the IDE's logcat, you can define the following macro, which uses the __android_log_print() function:

#include <android/log.h>#define ...

Get Hands-On Machine Learning with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.