Reputation: 74
I am trying to use tensorflow using android NDK. I have setup everything as mentioned in this answer (Link)
Answer: I use Native TFL with C-API in the following way:
SETUP:
Here is my project structure
app/
|-- src/
| |-- main/
| |-- cpp/
| | |-- UpscalingShader.cpp
| | |-- UpscalingShader.h
| | |-- RgbAToRgb.cpp
| | |-- RgbAToRgb.h
| | |-- GlUtil.cpp
| | |-- GlUtil.h
| | |-- DebugText.cpp
| | |-- DebugText.h
| | |-- CMakeLists.txt
| |-- jniLibs/
| | |-- arm64-v8a\
| | | |-- // all the header files in (https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/c) and other files required for the project
| | | |-- libtensorflowlite.so (Which the answer expects me to place this '.so' file here)
| | | |...
|-- build.gradle
|-- ...
This is my CMakeLists.txt file:
# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)
# Declares the project name.
project("my_project")
# Set the JNI directory where the TensorFlow Lite library and headers are located
set(JNI_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp/jniLibs)
# Define the TensorFlow Lite library as an imported library
add_library(tflite-lib SHARED IMPORTED)
# Set the location of the TensorFlow Lite library
set_target_properties(
tflite-lib
PROPERTIES IMPORTED_LOCATION
/path/to/app/src/main/jniLibs/arm64-v8a/libtensorflowlite_jni.so
)
# Include the TensorFlow Lite headers
include_directories(${JNI_DIR}/include)
# Create the main library
add_library(${CMAKE_PROJECT_NAME} SHARED
my_file.cpp
UpscalingShader.cpp
UpscalingEffect.cpp
RgbAToRgb.cpp
GlUtil.cpp
DebugText.cpp
)
# Link libraries to the main library
target_link_libraries(${CMAKE_PROJECT_NAME}
android
log
tflite-lib
)
I did everything accordingly, but I am getting the following error while trying to run my app.
In file included from /path/to/app/src/main/cpp/UpscalingEffect.cpp:5:
In file included from /path/to/app/src/main/cpp/UpscalingEffect.h:9:
In file included from /path/to/app/src/main/cpp/UpscalingShader.h:10:
/path/to/app/src/main/cpp/./tensorflow/tensorflow/lite/c/builtin_op_data.h:21:10: fatal error: 'tensorflow/lite/core/c/builtin_op_data.h' file not found
21 | #include "tensorflow/lite/core/c/builtin_op_data.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is the builtin_op_data.h (Which I copied from tensorflow/tensorflow/lite/c to here according to the answer)
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
#define TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
/// For documentation, see
/// third_party/tensorflow/lite/core/c/builtin_op_data.h
#include "tensorflow/lite/core/c/builtin_op_data.h"
#endif // TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
Upvotes: 1
Views: 36