How to use torch::nn in LibTorch for Android

Dear all,

I have develop a deep-learning model with the LibTorch which is C++ based Torch for an android application. To be specific, I use JNI in order to call C++ LibTorch code.
You can refer to the LibTorch_Android for LibTorch on the Android.

I hope to use below functions, but I cannot load the namespace, torch::nn.

  • torch::nn::functional::pad
  • torch::nn::functional::PadFuncOptions
  • torch::nn::functional::grid_sample
  • torch::nn::functional::GridSampleFuncOptions

I attach my CMakeLists.txt and native-lib.cpp which is called by JNI.
CMakeLists.txt

# LibTorch
file(GLOB PYTORCH_INCLUDE_DIRS "${PATH_BUILD}/pytorch_android*.aar/headers")
file(GLOB PYTORCH_LINK_DIRS "${PATH_BUILD}/pytorch_android*.aar/jni/${ANDROID_ABI}")
set(BUILD_SUBDIR ${ANDROID_ABI})
target_include_directories(${PROJECT_NAME} PRIVATE ${PYTORCH_INCLUDE_DIRS} ${PYTORCH_INCLUDE_DIRN})
find_library(PYTORCH_LIBRARY pytorch_jni PATHS ${PYTORCH_LINK_DIRS} NO_CMAKE_FIND_ROOT_PATH)

native-lib.cpp

#include "torch/script.h"
auto temp = torch::nn::functional::PadFuncOptions({1, 1, 1, 1});

Could I use torch::nn on Android? What should I do?

Best regards,
Vujadeyoon