summaryrefslogtreecommitdiff
path: root/contrib/TFLiteSharp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/TFLiteSharp')
-rw-r--r--contrib/TFLiteSharp/README.md92
-rw-r--r--contrib/TFLiteSharp/TFLiteNative/CMakeLists.txt67
-rw-r--r--contrib/TFLiteSharp/TFLiteNative/include/tflite_log.h65
-rw-r--r--contrib/TFLiteSharp/TFLiteNative/include/tflite_nativewrapper.h56
-rw-r--r--contrib/TFLiteSharp/TFLiteNative/src/tflite_nativewrapper.cpp142
-rw-r--r--contrib/TFLiteSharp/TFLiteNative/tflite-native.pc.in13
-rw-r--r--contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp.sln25
-rw-r--r--contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.Libraries.cs23
-rw-r--r--contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.TFLite.cs37
-rw-r--r--contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/TFLiteSharp.csproj52
-rw-r--r--contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Datatype.cs31
-rw-r--r--contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Interpreter.cs263
-rw-r--r--contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest.sln31
-rw-r--r--contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/Program.cs38
-rw-r--r--contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/TFLiteSharpTest.csproj12
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp.csproj54
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_App.cs65
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_Main.cs20
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/res/mobilenet_v1_1.0_224.tflitebin0 -> 16900960 bytes
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/res/mouse1.bmpbin0 -> 2764854 bytes
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/res/mouse_224.bmpbin0 -> 150582 bytes
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/shared/res/TFLiteTestApp.pngbin0 -> 10097 bytes
-rw-r--r--contrib/TFLiteSharp/TFLiteTestApp/tizen-manifest.xml14
-rw-r--r--contrib/TFLiteSharp/packaging/TFLiteSharp.manifest5
-rw-r--r--contrib/TFLiteSharp/packaging/TFLiteSharp.spec103
-rw-r--r--contrib/TFLiteSharp/packaging/tflite-native.manifest5
26 files changed, 1213 insertions, 0 deletions
diff --git a/contrib/TFLiteSharp/README.md b/contrib/TFLiteSharp/README.md
new file mode 100644
index 000000000..8e43be618
--- /dev/null
+++ b/contrib/TFLiteSharp/README.md
@@ -0,0 +1,92 @@
+# C-Sharp TFLite API Directory structure
+```
+.
+├── packaging
+│   ├── TFLiteSharp.manifest
+│   └── TFLiteSharp.spec
+├── README.md
+├── TFLiteNative
+│   ├── CMakeLists.txt
+│   ├── include
+│   │   ├── tflite_log.h
+│   │   └── tflite_nativewrapper.h
+│   ├── src
+│   │   └── tflite_nativewrapper.cpp
+│   └── tflite-native.pc.in
+├── TFLiteSharp
+│   ├── TFLiteSharp
+│   │   ├── src
+│   │   │   └── Interpreter.cs
+│   │   └── TFLiteSharp.csproj
+│   └── TFLiteSharp.sln
+└── TFLiteSharpTest
+ ├── TFLiteSharpTest
+ │   ├── Program.cs
+ │   └── TFLiteSharpTest.csproj
+ └── TFLiteSharpTest.sln
+```
+
+# Build C-Sharp TFLite
+gbs should be used to build TFLiteSharp package. nnfw is also built by gbs. As in most cases when building nnfw we won't intend to build TFLiteSharp hence we have separated its build process, so in order to build TFLiteSharp below command is needed:
+```
+nnfw$ gbs build --packaging-dir=contrib/TFLiteSharp/packaging/ --spec=TFLiteSharp.spec -A armv7l
+```
+This will first build the TFLiteNative package containing native c++ bindings between c# api and tflite api
+and then it will build TFLiteSharp(c# api package).
+
+Please use gbs.conf file corresponding to tizen image version. In most cases gbs.conf file should be same as the one which is used to build nnfw.
+# C-Sharp TFLite API list
+
+## Interpreter Class
+
+### Constructor
+
+The `Interpreter.cs` class drives model inference with TensorFlow Lite.
+
+#### Initializing an `Interpreter` With a Model File
+
+The `Interpreter` can be initialized with a model file using the constructor:
+
+```c#
+public Interpreter(string modelFile);
+```
+
+Number of threads available to the interpereter can be set by using the following function:
+```c#
+public void SetNumThreads(int num_threads)
+```
+
+### Running a model
+
+If a model takes only one input and returns only one output, the following will trigger an inference run:
+
+```c#
+interpreter.Run(input, output);
+```
+
+For models with multiple inputs, or multiple outputs, use:
+
+```c#
+interpreter.RunForMultipleInputsOutputs(inputs, map_of_indices_to_outputs);
+```
+
+The C# api also provides functions for getting the model's input and output indices given the name of tensors as input:
+
+```c#
+public int GetInputIndex(String tensorName)
+public int GetOutputIndex(String tensorName)
+```
+
+Developer can also enable or disable the use of NN API based on hardware capabilites:
+```c#
+public void SetUseNNAPI(boolean useNNAPI)
+```
+
+### Releasing Resources After Use
+
+An `Interpreter` owns resources. To avoid memory leak, the resources must be
+released after use by:
+
+```c#
+interpreter.Dispose();
+```
diff --git a/contrib/TFLiteSharp/TFLiteNative/CMakeLists.txt b/contrib/TFLiteSharp/TFLiteNative/CMakeLists.txt
new file mode 100644
index 000000000..8b58aac9c
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteNative/CMakeLists.txt
@@ -0,0 +1,67 @@
+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
new file mode 100644
index 000000000..cf51219fd
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteNative/include/tflite_log.h
@@ -0,0 +1,65 @@
+/*
+ * 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
new file mode 100644
index 000000000..7fddb5400
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteNative/include/tflite_nativewrapper.h
@@ -0,0 +1,56 @@
+/*
+ * 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
new file mode 100644
index 000000000..413304637
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteNative/src/tflite_nativewrapper.cpp
@@ -0,0 +1,142 @@
+/*
+ * 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
new file mode 100644
index 000000000..eec103acc
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteNative/tflite-native.pc.in
@@ -0,0 +1,13 @@
+# 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}
diff --git a/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp.sln b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp.sln
new file mode 100644
index 000000000..985466cef
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26730.16
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TFLiteSharp", "TFLiteSharp\TFLiteSharp.csproj", "{22D47176-D5AD-4AD4-8867-8788139DF71C}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {22D47176-D5AD-4AD4-8867-8788139DF71C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {22D47176-D5AD-4AD4-8867-8788139DF71C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {22D47176-D5AD-4AD4-8867-8788139DF71C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {22D47176-D5AD-4AD4-8867-8788139DF71C}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {1B276F69-8E79-4501-AF04-6D340690762B}
+ EndGlobalSection
+EndGlobal
diff --git a/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.Libraries.cs b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.Libraries.cs
new file mode 100644
index 000000000..db8d9f612
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.Libraries.cs
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ public const string TFLite = "libtflite-native.so";
+ }
+}
diff --git a/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.TFLite.cs b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.TFLite.cs
new file mode 100644
index 000000000..c7c7b24aa
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/Interop/Interop.TFLite.cs
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class TFLite
+ {
+ [DllImport(Libraries.TFLite, EntryPoint = "tflite_flatbuffermodel_BuildFromFile")]
+ internal static extern IntPtr TFLiteFlatBufferModelBuildFromFile(string path);
+
+ [DllImport(Libraries.TFLite, EntryPoint = "tflite_builder_interpreterBuilder")]
+ internal static extern IntPtr TFLiteBuilderInterpreterBuilder(ref IntPtr modelHandle);
+
+ [DllImport(Libraries.TFLite, EntryPoint = "tflite_interpreter_setNumThreads")]
+ internal static extern void TFLiteInterpreterSetNumThreads(int numThreads);
+
+ [DllImport(Libraries.TFLite, EntryPoint = "tflite_interpreter_run")]
+ internal static extern IntPtr TFLiteInterpreterRun(ref IntPtr interpreterHandle, IntPtr values, int inpLen, int dataType);
+
+ }
+}
diff --git a/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/TFLiteSharp.csproj b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/TFLiteSharp.csproj
new file mode 100644
index 000000000..e0490bfb8
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/TFLiteSharp.csproj
@@ -0,0 +1,52 @@
+<Project>
+ <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
+
+ <PropertyGroup Label="Globals">
+ <TizenProjectExtensionsPath>$(MSBuildExtensionsPath)\Tizen\VisualStudio\</TizenProjectExtensionsPath>
+ </PropertyGroup>
+
+ <Import Project="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props" Condition="Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props')" />
+
+ <PropertyGroup>
+ <OutputType>Library</OutputType>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+
+ <!--
+ This Property Group for msbuild command line.
+ If project build on Visual Studio, it would be set automatically through the certificate manager.
+ <PropertyGroup>
+ <AuthorPath>author_test.p12</AuthorPath>
+ <AuthorPass>author_test</AuthorPass>
+ <DistributorPath>tizen-distributor-signer.p12</DistributorPath>
+ <DistributorPass>tizenpkcs12passfordsigner</DistributorPass>
+ </PropertyGroup>
+ -->
+
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugType>portable</DebugType>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>None</DebugType>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Remove="res\**" />
+ <EmbeddedResource Remove="res\**" />
+ <None Remove="res\**" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <Folder Include="Interop\" />
+ <Folder Include="lib\" />
+ </ItemGroup>
+
+ <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
+ <Import Project="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets" Condition="Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets')" />
+
+ <!-- Install Check 'Visual Studio for Tizen' for developing on Visual Studio -->
+ <Target Name="TizenVsixInstallCheck" BeforeTargets="CompileDesignTime">
+ <Warning Condition="!Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props')" Text="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props is not exist.&#xA; you need to check if 'Visual Studio for Tizen' is installed" />
+ <Warning Condition="!Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets')" Text="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets is not exist.\&#xA; you need to check if 'Visual Studio for Tizen' is installed" />
+ </Target>
+</Project>
+
diff --git a/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Datatype.cs b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Datatype.cs
new file mode 100644
index 000000000..404d1663e
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Datatype.cs
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+/** Type of elements in a {@link TfLiteTensor}. */
+enum DataType
+{
+ /** 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
+}
diff --git a/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Interpreter.cs b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Interpreter.cs
new file mode 100644
index 000000000..f1b4a8e07
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharp/TFLiteSharp/src/Interpreter.cs
@@ -0,0 +1,263 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace TFLite
+{
+
+ /// <summary>
+ /// Driver class to drive model inference with TensorFlow Lite. Interpreter
+ /// encapsulates a pre-trained model file in whihc the operations are performed
+ /// @class Interpreter
+ /// </summary>
+ public class Interpreter : IDisposable
+ {
+ // Handle to hold the model instance
+ private IntPtr m_modelHandle;
+ // Handle to hold the interpreter instance
+ private IntPtr m_interpreterHandle;
+
+ /// <summary>
+ /// Interpreter Constructor. Inititalizes an interpreter.
+ /// </summary>
+ ///<param name="modelPath">a File of a pre-trained TF Lite model. </param>
+ public Interpreter(string modelPath)
+ {
+ //Constructor to initialize the interpreter with a model file
+ m_modelHandle = Interop.TFLite.TFLiteFlatBufferModelBuildFromFile(modelPath);
+ if(m_modelHandle == IntPtr.Zero)
+ {
+ //TODO: routine for handling null pointer.
+ }
+ m_interpreterHandle = Interop.TFLite.TFLiteBuilderInterpreterBuilder(ref m_modelHandle);
+ if (m_interpreterHandle == IntPtr.Zero)
+ {
+ //TODO: routine for handling null pointer.
+ }
+ }
+
+ /// <summary>
+ /// Set the number of threads available to the interpreter.
+ /// </summary>
+ /// <param name="numThreads">Number of threads.</param>
+ public void SetNumThreads(int numThreads)
+ {
+ Interop.TFLite.TFLiteInterpreterSetNumThreads(numThreads);
+ return;
+ }
+
+ /// <summary>
+ /// Runs model inference if the model takes only one input, and provides only
+ /// one output.
+ /// </summary>
+ /// <param name="input">input an array or multidimensional array.</param>
+ /// <param name="output">outputs a multidimensional array of output data.</param>
+ public void Run(Array input, ref Array output)
+ {
+ Array[] inputs = { input };
+ Dictionary<int, Array> outputs = new Dictionary<int, Array>();
+
+ RunForMultipleInputsOutputs(inputs, ref outputs);
+ output = outputs[0];
+
+ return;
+ }
+
+ /// <summary>
+ /// Runs model inference if the model takes multiple inputs, or returns multiple
+ /// outputs.
+ /// </summary>
+ /// <param name="inputs">input an array of input data.</param>
+ /// <param name="outputs">outputs a map mapping output indices to multidimensional
+ /// arrays of output data.</param>
+ public void RunForMultipleInputsOutputs(Array[] inputs, ref Dictionary<int, Array> outputs)
+ {
+ if(m_interpreterHandle == IntPtr.Zero)
+ {
+ //TODO:: exception handling
+ }
+
+ if (inputs == null || inputs.Length == 0)
+ {
+ //TODO::throw new IllegalArgumentException("Input error: Inputs should not be null or empty.");
+ }
+
+ DataType[] dataTypes = new DataType[inputs.Length];//To be used in multi-dimensional case
+
+ for (int i = 0; i < inputs.Length; ++i)
+ {
+ dataTypes[i] = DataTypeOf(inputs[i]);
+ }
+
+ //TODO:: Support for multi dimesional array to be added.
+ IntPtr pnt = Marshal.AllocHGlobal(inputs[0].Length);
+
+ switch (dataTypes[0])
+ {
+ case DataType.INT32:
+ Marshal.Copy((int[])inputs[0], 0, pnt, inputs[0].Length);
+ break;
+ case DataType.FLOAT32:
+ Marshal.Copy((float[])inputs[0], 0, pnt, inputs[0].Length);
+ break;
+ case DataType.UINT8:
+ Marshal.Copy((byte[])inputs[0], 0, pnt, inputs[0].Length);
+ break;
+ case DataType.INT64:
+ Marshal.Copy((long[])inputs[0], 0, pnt, inputs[0].Length);
+ break;
+ default:
+ Marshal.Copy((byte[])inputs[0], 0, pnt, inputs[0].Length);
+ break;
+ }
+
+ //Currently this handles only single input with single dimension.
+ IntPtr outputsHandles = Interop.TFLite.TFLiteInterpreterRun(ref m_interpreterHandle, pnt, inputs[0].Length, (int)dataTypes[0]);
+
+ if (outputsHandles == null)
+ {
+ //throw new IllegalStateException("Internal error: Interpreter has no outputs.");
+ }
+
+ switch (dataTypes[0])
+ {
+ case DataType.INT32:
+ int[] managedArrayInt = new int[inputs[0].Length];
+ Marshal.Copy(outputsHandles, managedArrayInt, 0, inputs[0].Length);
+ outputs.Add(0, managedArrayInt);
+ break;
+ case DataType.FLOAT32:
+ float[] managedArrayFloat = new float[inputs[0].Length];
+ Marshal.Copy(outputsHandles, managedArrayFloat, 0, inputs[0].Length);
+ outputs.Add(0, managedArrayFloat);
+ break;
+ case DataType.UINT8:
+ byte[] managedArrayByte = new byte[inputs[0].Length];
+ Marshal.Copy(outputsHandles, managedArrayByte, 0, inputs[0].Length);
+ outputs.Add(0, managedArrayByte);
+ break;
+ case DataType.INT64:
+ long[] managedArrayLong = new long[inputs[0].Length];
+ Marshal.Copy(outputsHandles, managedArrayLong, 0, inputs[0].Length);
+ outputs.Add(0, managedArrayLong);
+ break;
+ default:
+ byte[] managedArrayDefault = new byte[inputs[0].Length];
+ Marshal.Copy(outputsHandles, managedArrayDefault, 0, inputs[0].Length);
+ outputs.Add(0, managedArrayDefault);
+ break;
+ }
+ return;
+ }
+
+ static DataType DataTypeOf(Array a)
+ {
+ if (a.GetValue(0).GetType()==typeof(int))
+ {
+ return DataType.INT32;
+ }
+ else if (a.GetValue(0).GetType() == typeof(float))
+ {
+ return DataType.FLOAT32;
+ }
+ else if (a.GetValue(0).GetType() == typeof(byte))
+ {
+ return DataType.UINT8;
+ }
+ else if(a.GetValue(0).GetType() == typeof(long))
+ {
+ return DataType.INT64;
+ }
+ else
+ {
+ return DataType.UINT8;
+ //TODO: throw exception
+ }
+
+ }
+
+ /// <summary>
+ /// Resizes idx-th input of the native model to the given dims.
+ /// </summary>
+ /// <param name="idx">index of the input.</param>
+ /// <param name="dims">Dimensions to which input needs to be resized.</param>
+ public void ResizeInput(int idx, int[] dims)
+ {
+ return;
+ }
+
+ /// <summary>
+ /// Gets index of an input given the tensor name of the input.
+ /// </summary>
+ /// <param name="tensorName">Name of the tensor.</param>
+ public int GetInputIndex(string tensorName)
+ {
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets index of output given the tensor name of the input.
+ /// </summary>
+ /// <param name="tensorName">Name of the tensor.</param>
+ public int GetOutputIndex(string tensorName)
+ {
+ return 0;
+ }
+
+ /// <summary>
+ /// Turns on/off Android NNAPI for hardware acceleration when it is available.
+ /// </summary>
+ /// <param name="useNNAPI">set the boolean value to turn on/off nnapi.</param>
+ public void SetUseNNAPI(bool useNNAPI)
+ {
+ return;
+ }
+
+ /// <summary>
+ /// Release resources associated with the Interpreter.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ protected virtual void Dispose(bool bDisposing)
+ {
+ if (m_interpreterHandle != IntPtr.Zero)
+ {
+ // Call the function to dispose this class
+ m_interpreterHandle = IntPtr.Zero;
+ }
+
+ if (bDisposing)
+ {
+ // No need to call the finalizer since we've now cleaned
+ // up the unmanaged memory
+ GC.SuppressFinalize(this);
+ }
+ }
+
+ // This finalizer is called when Garbage collection occurs, but only if
+ // the IDisposable.Dispose method wasn't already called.
+ ~Interpreter()
+ {
+ Dispose(false);
+ }
+ }
+}
diff --git a/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest.sln b/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest.sln
new file mode 100644
index 000000000..e260a72c7
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26730.16
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TFLiteSharpTest", "TFLiteSharpTest\TFLiteSharpTest.csproj", "{D35A178F-9EF3-4B07-9E53-A91AA7A030B3}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TFLiteSharp", "..\TFLiteSharp\TFLiteSharp\TFLiteSharp.csproj", "{C06BC425-9BC3-43C7-A9D3-E12849E0C129}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D35A178F-9EF3-4B07-9E53-A91AA7A030B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D35A178F-9EF3-4B07-9E53-A91AA7A030B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D35A178F-9EF3-4B07-9E53-A91AA7A030B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D35A178F-9EF3-4B07-9E53-A91AA7A030B3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C06BC425-9BC3-43C7-A9D3-E12849E0C129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C06BC425-9BC3-43C7-A9D3-E12849E0C129}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C06BC425-9BC3-43C7-A9D3-E12849E0C129}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C06BC425-9BC3-43C7-A9D3-E12849E0C129}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {8F946511-2BE4-40A5-A48C-A5684C62755D}
+ EndGlobalSection
+EndGlobal
diff --git a/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/Program.cs b/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/Program.cs
new file mode 100644
index 000000000..e559bec36
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/Program.cs
@@ -0,0 +1,38 @@
+using System;
+
+namespace TFLiteSharpTest
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ //Constructing a new interpreter instance from the modelfile
+ TFLite.Interpreter interpreter = new TFLite.Interpreter("modelpath/modelfile.tflite");
+ Console.WriteLine("Interpreter Built Successfully");
+
+ //Setting the number of threads of the interpreter
+ interpreter.SetNumThreads(1);
+
+ //Declaring input and output variables;
+ Array input = new int[5] { 1, 2, 3, 4, 5 };
+ Array output = new int[5];
+
+ //Call to invoke the interpreter and run the inference to populate output
+ interpreter.Run(input, out output);
+ Console.WriteLine("Output generated Successfully");
+
+ //get input, output indices
+ Console.WriteLine("Input index for tensorname: " + interpreter.GetInputIndex("tensorname"));
+ Console.WriteLine("Output index for tensorname: " + interpreter.GetOutputIndex("tensorname"));
+
+ //Resizing the dimensions
+ int[] dims = new int[3] { 1, 2, 3 };
+ interpreter.ResizeInput(1, dims);
+
+ //Disposing the interpreter to free resources at the end
+ interpreter.Dispose();
+
+ Console.WriteLine("Run Complete");
+ }
+ }
+}
diff --git a/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/TFLiteSharpTest.csproj b/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/TFLiteSharpTest.csproj
new file mode 100644
index 000000000..b143ee598
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteSharpTest/TFLiteSharpTest/TFLiteSharpTest.csproj
@@ -0,0 +1,12 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>netcoreapp2.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\TFLiteSharp\TFLiteSharp\TFLiteSharp.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp.csproj b/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp.csproj
new file mode 100644
index 000000000..1c9ed6037
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp.csproj
@@ -0,0 +1,54 @@
+<Project>
+ <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
+
+ <!-- Setting Tizen Extension Path -->
+ <PropertyGroup Label="Globals">
+ <TizenProjectExtensionsPath>$(MSBuildExtensionsPath)\Tizen\VisualStudio\</TizenProjectExtensionsPath>
+ </PropertyGroup>
+
+ <!-- Import Tizen property in Tizen.NET SDK -->
+ <Import Project="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props" Condition="Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props')" />
+
+ <!-- Property Group for .NET Core Project -->
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+
+ <!-- Property Group for Tizen Project -->
+ <PropertyGroup>
+ <TizenCreateTpkOnBuild>true</TizenCreateTpkOnBuild>
+ <PackageTargetFallback>$(PackageTargetFallback);portable-net45+wp80+win81+wpa81</PackageTargetFallback>
+ </PropertyGroup>
+
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugType>portable</DebugType>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>None</DebugType>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Folder Include="lib\" />
+ <Folder Include="res\" />
+ </ItemGroup>
+
+ <!-- Include Nuget Package for Tizen Project building -->
+ <ItemGroup>
+ <PackageReference Include="Tizen.NET" Version="3.0.0" />
+ <PackageReference Include="Tizen.NET.Sdk" Version="1.0.1" />
+ <PackageReference Include="Xamarin.Forms.Platform.Tizen" Version="2.3.5-r256-001" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\TFLiteSharp\TFLiteSharp\TFLiteSharp.csproj" />
+ </ItemGroup>
+
+ <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
+ <Import Project="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets" Condition="Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets')" />
+
+ <!-- Install Check 'Visual Studio for Tizen' for developing on Visual Studio -->
+ <Target Name="TizenVsixInstallCheck" BeforeTargets="CompileDesignTime">
+ <Warning Condition="!Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props')" Text="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.props is not exist.&#xA; you need to check if 'Visual Studio for Tizen' is installed" />
+ <Warning Condition="!Exists('$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets')" Text="$(TizenProjectExtensionsPath)Tizen.NET.ProjectType.targets is not exist.\&#xA; you need to check if 'Visual Studio for Tizen' is installed" />
+ </Target>
+</Project>
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_App.cs b/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_App.cs
new file mode 100644
index 000000000..49a08604d
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_App.cs
@@ -0,0 +1,65 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Xamarin.Forms;
+
+namespace TFLiteTestApp
+{
+ public class App : Application
+ {
+ public App()
+ {
+ TFLite.Interpreter interpreter = null;
+ try
+ {
+ interpreter = new TFLite.Interpreter(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mobilenet_v1_1.0_224.tflite");
+ }
+ catch(Exception e)
+ {
+ Tizen.Log.Debug("tflite", "Error: " + e);
+ }
+
+ Tizen.Log.Debug("tflite", "Interpreter Initialised");
+ Array Output = new byte[1000];
+
+ Array input = new byte[150582];
+ input = File.ReadAllBytes(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mouse_224.bmp");
+
+ interpreter.Run(input, ref Output);
+ //val variable to check if the Output array is being populated or not.
+ byte val = ((byte[])Output)[0];
+ // The root page of your application
+ MainPage = new ContentPage
+ {
+ Content = new StackLayout
+ {
+ VerticalOptions = LayoutOptions.Center,
+ Children = {
+ new Label {
+ HorizontalTextAlignment = TextAlignment.Center,
+ Text = "Welcome to Xamarin Forms!"
+ }
+ }
+ }
+ };
+ }
+
+ protected override void OnStart()
+ {
+ // Handle when your app starts
+ }
+
+ protected override void OnSleep()
+ {
+ // Handle when your app sleeps
+ }
+
+ protected override void OnResume()
+ {
+ // Handle when your app resumes
+ }
+ }
+}
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_Main.cs b/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_Main.cs
new file mode 100644
index 000000000..2a8f747a4
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/TFLiteTestApp_Main.cs
@@ -0,0 +1,20 @@
+using System;
+
+namespace TFLiteTestApp
+{
+ class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
+ {
+ protected override void OnCreate()
+ {
+ base.OnCreate();
+ LoadApplication(new App());
+ }
+
+ static void Main(string[] args)
+ {
+ var app = new Program();
+ global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);
+ app.Run(args);
+ }
+ }
+}
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/res/mobilenet_v1_1.0_224.tflite b/contrib/TFLiteSharp/TFLiteTestApp/res/mobilenet_v1_1.0_224.tflite
new file mode 100644
index 000000000..d34691eb6
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/res/mobilenet_v1_1.0_224.tflite
Binary files differ
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/res/mouse1.bmp b/contrib/TFLiteSharp/TFLiteTestApp/res/mouse1.bmp
new file mode 100644
index 000000000..1734ca318
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/res/mouse1.bmp
Binary files differ
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/res/mouse_224.bmp b/contrib/TFLiteSharp/TFLiteTestApp/res/mouse_224.bmp
new file mode 100644
index 000000000..ccfed6ad3
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/res/mouse_224.bmp
Binary files differ
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/shared/res/TFLiteTestApp.png b/contrib/TFLiteSharp/TFLiteTestApp/shared/res/TFLiteTestApp.png
new file mode 100644
index 000000000..9f3cb9860
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/shared/res/TFLiteTestApp.png
Binary files differ
diff --git a/contrib/TFLiteSharp/TFLiteTestApp/tizen-manifest.xml b/contrib/TFLiteSharp/TFLiteTestApp/tizen-manifest.xml
new file mode 100644
index 000000000..62a8d4c7c
--- /dev/null
+++ b/contrib/TFLiteSharp/TFLiteTestApp/tizen-manifest.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="4" package="org.tizen.example.TFLiteTestApp" version="1.0.0">
+ <profile name="common" />
+ <ui-application appid="org.tizen.example.TFLiteTestApp"
+ exec="TFLiteTestApp.dll"
+ type="dotnet"
+ multiple="false"
+ taskmanage="true"
+ nodisplay="false"
+ launch_mode="single">
+ <label>TFLiteTestApp</label>
+ <icon>TFLiteTestApp.png</icon>
+ </ui-application>
+</manifest>
diff --git a/contrib/TFLiteSharp/packaging/TFLiteSharp.manifest b/contrib/TFLiteSharp/packaging/TFLiteSharp.manifest
new file mode 100644
index 000000000..75b0fa5e3
--- /dev/null
+++ b/contrib/TFLiteSharp/packaging/TFLiteSharp.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
diff --git a/contrib/TFLiteSharp/packaging/TFLiteSharp.spec b/contrib/TFLiteSharp/packaging/TFLiteSharp.spec
new file mode 100644
index 000000000..dcb65a864
--- /dev/null
+++ b/contrib/TFLiteSharp/packaging/TFLiteSharp.spec
@@ -0,0 +1,103 @@
+Name: TFLiteSharp
+Summary: Tensorflow lite native cpp wrapper and C# API
+Version: 1.0.0
+Release: 1
+Group: Development/Libraries
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Source1: %{name}.manifest
+Source2: tflite-native.manifest
+
+%description
+%{summary}
+
+%package TFLiteNative
+Summary: Tensorflow lite native cpp wrapper
+Group: Development/Libraries
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(tensorflow-lite)
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description TFLiteNative
+Native CPP Wrapper for Tensorflow lite
+
+%package TFLiteNative-devel
+Summary: Tensorflow lite native cpp wrapper (Development)
+Requires: %{name} = %{version}-%{release}
+
+%description TFLiteNative-devel
+Tensorflow lite native cpp wrapper (Development)
+
+%package TFLiteSharp
+Summary: Tensorflow lite API for C#
+Group: Development/Libraries
+AutoReqProv: no
+ExcludeArch: aarch64
+
+BuildRequires: dotnet-build-tools
+
+%define Assemblies TFLiteSharp
+
+%description TFLiteSharp
+Tensorflow lite API for C#
+
+%dotnet_import_sub_packages
+
+%prep
+%setup -q
+cp %{SOURCE1} .
+cp %{SOURCE2} .
+%if 0%{?tizen:1}
+%define TARGET_OS tizen
+%else
+%define TARGET_OS linux
+%endif
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%if "%{TARGET_OS}" == "tizen"
+cmake VERBOSE=1 -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
+ -DLIB_INSTALL_DIR=%{_libdir} -DINCLUDE_INSTALL_DIR=%{_includedir} \
+ -DLIB_PATH=%{_lib} -DTIZEN=1 contrib/TFLiteSharp/TFLiteNative
+%else
+cmake VERBOSE=1 -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
+ -DLIB_INSTALL_DIR=%{_libdir} -DINCLUDE_INSTALL_DIR=%{_includedir} \
+ -DLIB_PATH=%{_lib} contrib/TFLiteSharp/TFLiteNative
+%endif
+
+make %{?_smp_mflags}
+
+cd contrib/TFLiteSharp/
+for ASM in %{Assemblies}; do
+%dotnet_build $ASM
+%dotnet_pack $ASM
+done
+
+%install
+%make_install
+cd contrib/TFLiteSharp/TFLiteSharp
+for ASM in %{Assemblies}; do
+%dotnet_install $ASM
+done
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%license LICENSE
+
+%files TFLiteNative
+%manifest tflite-native.manifest
+%{_libdir}/libtflite-native.so*
+
+%files TFLiteNative-devel
+%{_includedir}/*
+%{_libdir}/pkgconfig/tflite-native.pc
+%{_libdir}/libtflite-native.so*
+
+%files TFLiteSharp
+%attr(644,root,root) %{dotnet_assembly_files}
diff --git a/contrib/TFLiteSharp/packaging/tflite-native.manifest b/contrib/TFLiteSharp/packaging/tflite-native.manifest
new file mode 100644
index 000000000..75b0fa5e3
--- /dev/null
+++ b/contrib/TFLiteSharp/packaging/tflite-native.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>