Open ichernob opened 3 years ago
UPD. I even attempted to clone the whole repository and build NativeApp.
android-demo-app\NativeApp\app\CMakeLists.txt : C/C++ debug|armeabi-v7a : CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: FBJNI_LIBRARY linked by target "pytorch_nativeapp" in directory android-demo-app/NativeApp/app PYTORCH_LIBRARY linked by target "pytorch_nativeapp" in directory android-demo-app/NativeApp/app
cc: @jeffxtang @IvanKobzarev
any news on that? I'm having the same issue with the CMake error mentioned above
It even doesn't compile.
I've copied code from tutorial first - no result I've copied code from NativeApp - no result.
For some reason torch/script.h could not be determined despite the fact that pytorch_android aar downloaded and extracted and cmake build completed! my CMakeLists.txt `cmake_minimum_required(VERSION 3.10.2) set(TARGET pytorchnative) project(${TARGET} CXX) set(CMAKE_CXX_STANDARD 14) set(build_DIR ${CMAKE_SOURCE_DIR}/build) set(pytorch_testapp_cpp_DIR ${CMAKE_CURRENT_LIST_DIR}/src/main/cpp) set(BUILD_SUBDIR ${ANDROID_ABI})
file(GLOB pytorch_testapp_SOURCES ${pytorch_testapp_cpp_DIR}/pytorchnative.cpp) add_library(${TARGET} SHARED ${pytorch_testapp_SOURCES})
file(GLOB PYTORCH_INCLUDE_DIRS "${build_DIR}/pytorch_android.aar/headers") file(GLOB PYTORCH_LINK_DIRS "${build_DIR}/pytorch_android.aar/jni/${ANDROID_ABI}")
target_compile_options(${TARGET} PRIVATE -fexceptions)
find_library(PYTORCH_LIBRARY pytorch_jni PATHS ${PYTORCH_LINK_DIRS} NO_CMAKE_FIND_ROOT_PATH) find_library(FBJNI_LIBRARY fbjni PATHS ${PYTORCH_LINK_DIRS} NO_CMAKE_FIND_ROOT_PATH)
find_library(log-lib log)
target_link_libraries(${TARGET} ${PYTORCH_LIBRARY} ${FBJNI_LIBRARY} ${log-lib})`
my app.build.gradle: `plugins { id 'com.android.application' id 'kotlin-android' }
repositories { jcenter() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } flatDir { dirs 'aars' } }
android { configurations { extractForNativeBuild } compileSdkVersion 30 buildToolsVersion "30.0.3"
// cppFlags "-std=c++14" arguments "-DANDROID_STL=c++_shared" } } ndk { abiFilters 'arm64-v8a' } }
}
dependencies {
}
task extractAARForNativeBuild { doLast { configurations.extractForNativeBuild.files.each { def file = it.absoluteFile copy { from zipTree(file) into "$buildDir/$file.name" include "headers/" include "jni/" } } } }
tasks.whenTaskAdded { task -> if (task.name.contains('externalNativeBuild')) { task.dependsOn(extractAARForNativeBuild) } }`
my pytorchnative.cpp: `#include <android/log.h>
include
include
include
include
include
define ALOGI(...) \
android_log_print(ANDROID_LOG_INFO, "PyTorchNativeApp", VA_ARGS__)
define ALOGE(...) \
android_log_print(ANDROID_LOG_ERROR, "PyTorchNativeApp", VA_ARGS__)
include "jni.h"
//#include <opencv2/opencv.hpp>
include <torch/script.h>
namespace pytorchnative { namespace { // torch::Tensor warp_perspective(torch::Tensor image, torch::Tensor warp) { // cv::Mat image_mat(/rows=/image.size(0), // /cols=/image.size(1), // /type=/CV_32FC1, // /data=/image.data_ptr());
// cv::Mat warp_mat(/rows=/warp.size(0),
// /cols=/warp.size(1),
// /type=/CV_32FC1,
// /data=/warp.data_ptr());
//
// cv::Mat output_mat;
// cv::warpPerspective(image_mat, output_mat, warp_mat, /dsize=/{8, 8});
//
// torch::Tensor output =
// torch::from_blob(output_mat.ptr(), /sizes=/{8, 8});
// return output.clone();
// }
//
// static auto registry =
// torch::RegisterOperators("my_ops::warp_perspective", &warp_perspective);
} // namespace pytorch_nativeapp
//extern "C" JNIEXPORT jstring JNICALL // Java_com_harman_pytorchnative_MainActivity_stringFromJNI
JNIEXPORT jint JNI_OnLoad(JavaVM vm, void ) { JNIEnv *env; if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) { return JNI_ERR; } jclass c = env->FindClass("com/harman/pytorchnative/NativeClient$NativePeer"); if (c == nullptr) { return JNI_ERR; }
static const JNINativeMethod methods[] = { {"loadAndForwardModel", "(Ljava/lang/String;)V", (void *)pytorchnative::loadAndForwardModel}, }; int rc = env->RegisterNatives(c, methods, sizeof(methods) / sizeof(JNINativeMethod));
if (rc != JNI_OK) { return rc; }
return JNI_VERSION_1_6; }`
It stops with error: PytorchNative\app\src\main\cpp\pytorchnative.cpp:15:10: fatal error: 'torch/script.h' file not found However I do have extracted aar under build directory with necessary files: build\pytorch_android-1.6.0-SNAPSHOT.aar\headers\torch\script.h
How to made it visible? Has that tutorial ever worked????