Support nnfw. If enable-nnfw is on, it will use nnfw.
**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped
Signed-off-by: jijoong.moon <jijoong.moon@samsung.com>
nnstreamer_filter_tflite_deps = [tflite_dep, thread_dep, libdl_dep, glib_dep, gst_dep, nnstreamer_dep]
+ if get_option('enable-nnfw')
+ nnapi_lib = dependency('nnfw', required: true)
+ if nnapi_lib.found()
+ nnstreamer_filter_tflite_deps += nnapi_lib
+ else
+ error('Cannot find nnfw')
+ endif
+ endif
+
shared_library('nnstreamer_filter_tensorflow-lite',
nnstreamer_filter_tflite_sources,
cpp_args: ['-Wno-sign-compare'],
return -2;
}
- /* Set inference path of tensorflow-lite */
- interpreter->UseNNAPI (use_nnapi);
+ interpreter->UseNNAPI(use_nnapi);
+
+#ifdef ENABLE_NNFW
+ if(use_nnapi){
+ nnfw_delegate.reset(new ::nnfw::tflite::NNAPIDelegate);
+ if(nnfw_delegate->BuildGraph(interpreter.get()) != kTfLiteOk){
+ GST_ERROR("Fail to BuildGraph");
+ return -3;
+ }
+ }
+#endif
+
+ g_message ("interpreter->UseNNAPI: %d" , use_nnapi);
/** set allocation type to dynamic for in/out tensors */
int tensor_idx;
tensors_idx.push_back (tensor_idx);
}
+#ifdef ENABLE_NNFW
+ if(use_nnapi){
+ if(nnfw_delegate->Invoke(interpreter.get()) != kTfLiteOk){
+ GST_ERROR ("Failed to invoke");
+ return -3;
+ }
+ }else{
+ if (interpreter->Invoke () != kTfLiteOk) {
+ GST_ERROR ("Failed to invoke");
+ return -3;
+ }
+ }
+#else
if (interpreter->Invoke () != kTfLiteOk) {
GST_ERROR ("Failed to invoke");
return -3;
}
+#endif
/** if it is not `nullptr`, tensorflow makes `free()` the memory itself. */
int tensorSize = tensors_idx.size ();
#include <tensorflow/contrib/lite/model.h>
#include <tensorflow/contrib/lite/kernels/register.h>
+#ifdef ENABLE_NNFW
+#include "tflite/ext/nnapi_delegate.h"
+#endif
+
/**
* @brief ring cache structure
*/
std::unique_ptr <tflite::Interpreter> interpreter;
std::unique_ptr <tflite::FlatBufferModel> model;
+#ifdef ENABLE_NNFW
+ std::unique_ptr <nnfw::tflite::NNAPIDelegate> nnfw_delegate;
+#endif
+
tensor_type getTensorType (TfLiteType tfType);
int getTensorDim (int tensor_idx, tensor_dim dim);
};
add_project_arguments('-D__TIZEN__=1', language: ['c', 'cpp'])
endif
+# nnfw
+if get_option('enable-nnfw')
+ add_project_arguments('-DENABLE_NNFW=1', language: ['c', 'cpp'])
+endif
+
+
# Build nnstreamer (common, plugins)
subdir('gst')
option('enable-tizen', type: 'boolean', value: false)
option('enable-element-restriction', type: 'boolean', value: false) # true to restrict gst-elements in api
option('restricted-elements', type: 'string', value: '')
+option('enable-nnfw', type: 'boolean', value: false)
%define enable_tf false
%endif
-meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -Dinstall-example=true -Denable-tensorflow=%{enable_tf} -Denable-pytorch=false -Denable-caffe2=false %{api} -Denable-env-var=false -Denable-symbolic-link=false -Denable-tizen=true build
+meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -Dinstall-example=true -Denable-tensorflow=%{enable_tf} -Denable-pytorch=false -Denable-caffe2=false %{api} -Denable-env-var=false -Denable-symbolic-link=false -Denable-tizen=true build -Denable-nnfw=false
ninja -C build %{?_smp_mflags}