diff options
Diffstat (limited to 'contrib/TFLiteSharp/TFLiteNative')
5 files changed, 0 insertions, 343 deletions
diff --git a/contrib/TFLiteSharp/TFLiteNative/CMakeLists.txt b/contrib/TFLiteSharp/TFLiteNative/CMakeLists.txt deleted file mode 100644 index 8b58aac9c..000000000 --- a/contrib/TFLiteSharp/TFLiteNative/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(fw_name "tflite-native") - -PROJECT(${fw_name}) -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(LIB ${LIB_PATH}) -SET(LIBDIR ${PREFIX}/${LIB_PATH}) - -SET(INC_DIR include) -INCLUDE_DIRECTORIES(${INC_DIR}) - -INCLUDE(FindPkgConfig) - -SET(COMMON_DEPS "tensorflow-lite") -SET(PC_DEPS "capi-base-common") - -IF (TIZEN) - MESSAGE("Building for Tizen") - SET(TIZEN_DEPS "dlog") - PKG_CHECK_MODULES(${fw_name} REQUIRED ${COMMON_DEPS} ${TIZEN_DEPS}) - ADD_DEFINITIONS("-D__TIZEN__") -ELSE () - MESSAGE("Building for Linux") - PKG_CHECK_MODULES(${fw_name} REQUIRED ${COMMON_DEPS}) -ENDIF () - -FOREACH(flag ${${fw_name}_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC -Wall -Werror") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") - -ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") - -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIBDIR}") - -aux_source_directory(src SOURCES) -ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) - -TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) - -SET_TARGET_PROPERTIES(${fw_name} - PROPERTIES - VERSION ${FULLVER} - SOVERSION ${MAJORVER} - CLEAN_DIRECT_OUTPUT 1 -) - -INSTALL(TARGETS ${fw_name} DESTINATION ${LIB}) -INSTALL( - DIRECTORY ${INC_DIR}/ DESTINATION include/ - FILES_MATCHING - PATTERN "${INC_DIR}/*.h" - ) - -SET(PC_NAME ${fw_name}) -SET(PC_REQUIRED ${pc_dependents}) -SET(PC_LDFLAGS -l${fw_name}) - -CONFIGURE_FILE( - ${fw_name}.pc.in - ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc - @ONLY -) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB}/pkgconfig) diff --git a/contrib/TFLiteSharp/TFLiteNative/include/tflite_log.h b/contrib/TFLiteSharp/TFLiteNative/include/tflite_log.h deleted file mode 100644 index cf51219fd..000000000 --- a/contrib/TFLiteSharp/TFLiteNative/include/tflite_log.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd 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 _TFLITE_LOG_H_ -#define _TFLITE_LOG_H_ - -#ifdef __cplusplus -extern "C" { -#endif /*__cplusplus*/ - -#define ERROR 1 -#define WARNING 2 -#define INFO 3 -#define DEBUG 4 - -#ifdef __TIZEN__ -#include <dlog/dlog.h> -#ifdef LOG_TAG -#undef LOG_TAG -#endif // LOG_TAG -#define LOG_TAG "TFLITE_NATIVE" - -#define TFLITE_NATIVE_LOG(log_level, format, args...) \ - do { \ - switch (log_level) { \ - case ERROR: \ - LOGE(format, ## args); \ - case WARNING: \ - LOGE(format, ## args); \ - default: \ - LOGI(format, ## args); \ - } \ - } while (0) -#else // __TIZEN__ -#define LEVEL_TO_STR(level) (\ - ((level) == ERROR) ? "ERROR" : \ - ((level) == WARNING) ? "WARNING" : \ - ((level) == INFO) ? "INFO": \ - ((level) == DEBUG) ? "DEBUG" : "DEFAULT") -#define TFLITE_NATIVE_LOG(log_level, format, args...) \ - do { \ - printf("%s: %s: ", LEVEL_TO_STR(log_level), __FILE__); \ - printf(format, ## args); \ - printf("\n"); \ - }while (0) -#endif // __TIZEN__ - -#ifdef __cplusplus -} -#endif /*__cplusplus*/ - -#endif /*_TFLITE_LOG_H*/ diff --git a/contrib/TFLiteSharp/TFLiteNative/include/tflite_nativewrapper.h b/contrib/TFLiteSharp/TFLiteNative/include/tflite_nativewrapper.h deleted file mode 100644 index 7fddb5400..000000000 --- a/contrib/TFLiteSharp/TFLiteNative/include/tflite_nativewrapper.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd 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 _TFLITE_NATIVEWRAPPER_H_ -#define _TFLITE_NATIVEWRAPPER_H_ - -#include "tensorflow/contrib/lite/kernels/register.h" -#include "tensorflow/contrib/lite/model.h" -#include "tensorflow/contrib/lite/string_util.h" -#include "tensorflow/contrib/lite/tools/mutable_op_resolver.h" - -#ifdef __cplusplus -extern "C" { -#endif /*__cplusplus*/ - -typedef enum -{ - /** 32-bit signed integer. */ - INT32 = 1, - - /** 32-bit single precision floating point. */ - FLOAT32 = 2, - - /** 8-bit unsigned integer. */ - UINT8 = 3, - - /** 64-bit signed integer. */ - INT64 = 4 -} TFLiteNativeType; - -void tflite_interpreter_setNumThreads(long* interpreterHandle, int numThreads); - -long long tflite_flatbuffermodel_BuildFromFile(char* modelPath); - -long long tflite_builder_interpreterBuilder(long* modelHandle); - -void* tflite_interpreter_run(long* interpreterHandle, void* values, int inputLength, int dataType); - -#ifdef __cplusplus -} -#endif /*__cplusplus*/ - -#endif /*_TFLITE_NATIVEWRAPPER_H_*/ diff --git a/contrib/TFLiteSharp/TFLiteNative/src/tflite_nativewrapper.cpp b/contrib/TFLiteSharp/TFLiteNative/src/tflite_nativewrapper.cpp deleted file mode 100644 index 413304637..000000000 --- a/contrib/TFLiteSharp/TFLiteNative/src/tflite_nativewrapper.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd 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. - */ - -#include <iostream> -#include "tflite_nativewrapper.h" -#include "tflite_log.h" -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <assert.h> - -int getNumBytes(TFLiteNativeType dataType) -{ - switch (dataType) { - case INT32: - return 4; - case FLOAT32: - return 4; - case UINT8: - return 1; - case INT64: - return 8; - default: - return 1; - } -} - -/// <summary> -/// Set the number of threads available to the interpreter. -/// </summary> -/// <param name="interpreterHandle">Handle of the interpreter instance.</param> -/// <param name="numThreads">Number of threads.</param> -void tflite_interpreter_setNumThreads(long* interpreterHandle, int numThreads) -{ - assert(interpreterHandle != nullptr); - tflite::Interpreter* interpreter = reinterpret_cast<tflite::Interpreter*>(*interpreterHandle); - - interpreter->SetNumThreads(numThreads); - - TFLITE_NATIVE_LOG(DEBUG, "Number of threads: %d", numThreads); - return; -} - -/// <summary> -/// Creates a Flat Buffer Model from the given .tflite model. -/// </summary> -/// <param name="modelPath">Path of the model.</param> -long long -tflite_flatbuffermodel_BuildFromFile(char* modelPath) -{ - if (modelPath == nullptr) { - TFLITE_NATIVE_LOG(ERROR, "Invalid parameter"); - return 0; - } - TFLITE_NATIVE_LOG(ERROR, "Model Path: %s", modelPath); - - if (access(modelPath, F_OK) == -1) { - TFLITE_NATIVE_LOG(ERROR, "Failed to access model [%s]", - strerror(errno)); - return 0; - } - - auto model = tflite::FlatBufferModel::BuildFromFile(modelPath); - - TFLITE_NATIVE_LOG(DEBUG, "Successfully loaded model"); - return reinterpret_cast<long>(model.release()); -} - -/// <summary> -/// Creates an interpreter instance taking the flatbuffer model as input. -/// </summary> -/// <param name="modelHandle">Address of the flatbuffer model.</param> -long long -tflite_builder_interpreterBuilder(long* modelHandle) -{ - assert(modelHandle != nullptr); - tflite::FlatBufferModel* model = reinterpret_cast<tflite::FlatBufferModel*>(*modelHandle); - - tflite::ops::builtin::BuiltinOpResolver resolver; - std::unique_ptr<tflite::Interpreter> interpreter; - - TfLiteStatus status = tflite::InterpreterBuilder (*model, resolver)(&interpreter); - - if (status != kTfLiteOk) { - TFLITE_NATIVE_LOG(DEBUG, "Cannot create interpreter"); - return 0; - } - TFLITE_NATIVE_LOG(DEBUG, "CheckPoint interpreter"); - return reinterpret_cast<long>(interpreter.release()); -} - -/// <summary> -/// Runs the inference given the inputs. -/// </summary> -/// <param name="interpreterHandle">Address of the interpreter instance.</param> -/// <param name="values">Input values for the model.</param> -/// <param name="inpLength">Length of the input.</param> -/// <param name="dataType">Data type key of the input.</param> -void* tflite_interpreter_run(long* interpreterHandle, void* values, int inputLength, - int dataType) -{ - assert(interpreterHandle != nullptr); - tflite::Interpreter* interpreter = reinterpret_cast<tflite::Interpreter*>(*interpreterHandle); - - int inputTensorIndex = interpreter->inputs()[0]; - - //TODO:: input tensor size will be passed as a parameter. It is hardcoded for now. - interpreter->ResizeInputTensor(inputTensorIndex, - { 1, 224, 224, 3 }); - - if (interpreter->AllocateTensors() != kTfLiteOk) { - TFLITE_NATIVE_LOG(ERROR, "Failed to allocate tensors!"); - return nullptr; - } - - float* inputTensorPointer = interpreter->typed_tensor<float>(inputTensorIndex); - - int numBytes = getNumBytes((TFLiteNativeType) dataType); - - memcpy(inputTensorPointer, values, inputLength * numBytes); - - if (interpreter->Invoke() != kTfLiteOk) { - TFLITE_NATIVE_LOG(ERROR, "Failed to invoke"); - } - - float* output = interpreter->typed_output_tensor<float>(0); - return output; -} - diff --git a/contrib/TFLiteSharp/TFLiteNative/tflite-native.pc.in b/contrib/TFLiteSharp/TFLiteNative/tflite-native.pc.in deleted file mode 100644 index eec103acc..000000000 --- a/contrib/TFLiteSharp/TFLiteNative/tflite-native.pc.in +++ /dev/null @@ -1,13 +0,0 @@ -# Package Information for pkg-config - -prefix=@PREFIX@ -exec_prefix=/usr -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDE_INSTALL_DIR@/ - -Name: @PC_NAME@ -Description: @PACKAGE_DESCRIPTION@ -Version: @VERSION@ -Requires: @PC_REQUIRED@ tensorflow-lite -Libs: -L${libdir} @PC_LDFLAGS@ -Cflags: -I${includedir} |