terryky / tflite_gles_app

GPU accelerated deep learning inference applications for RaspberryPi / JetsonNano / Linux PC using TensorflowLite GPUDelegate / TensorRT
MIT License
488 stars 130 forks source link

Implement Custom Ops in build #3

Open ragavendranbala opened 4 years ago

ragavendranbala commented 4 years ago

Hi @terryky , I want to load the hairsegmentation model in python but when i try to initialize the tflite model in interpreter, it always showing MaxPoolingWithArgmax2D ops error. Can you tell me how to build this custom ops with bazel when building tensorflow. if I'm wrong please tell me how to implement custom ops. Thanks in Advance

terryky commented 4 years ago

Hi @ragavendranbala,

I'm not familier with Tensorflow Lite python API, but It's easy to implement custom Op in C++ API. Please refer follows:

ragavendranbala commented 4 years ago

@terryky thanks for your reply, actually i wanted to build the plugin for android, i think , to make it work on android, i need to add this custom ops while building the plugin itelf. I have searched for links to reference the plugin in build. but no luck. i guess the build of plugin working on c++ only. I''m expecting your ideas for this

ragavendranbala commented 4 years ago

hi @terryky , I have built the plugin which custom ops. now i need to know, is this running on CPU or GPU? is there is any possibilities to make the ops to run on GPU?

terryky commented 4 years ago

Tensorflow Lite GPU Delegate supports following custom operations. If your implementation enables GPU Delegate, the custom ops run on GPU.

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/delegates/gpu/common/model_builder.cc#L2715-L2753

ragavendranbala commented 4 years ago

@terryky the link you have given having the ops functions, but i think it's not building with my plugin

bazel build -c opt --config android_arm64 --copt -Os --copt -DTFLITE_GPU_BINARY_RELEASE --copt -fvisibility=hidden --linkopt -s --strip always //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so

This is command I'm using to build my GPU delegate.

Should I add any files to make it work on GPU?

terryky commented 4 years ago

Does your app enable GPU Delegate ?

delegate = TfLiteGpuDelegateV2Create(&options);
interpreter->ModifyGraphWithDelegate(delegate)

https://github.com/terryky/tflite_gles_app/blob/master/common/util_tflite.cpp#L167-L174

ragavendranbala commented 4 years ago

@terryky The plugin I have created running deeplab v3 on smoothly but this tflite is hicking up , based on the deeplab performance, I think gpu delegate is enabled

soham24 commented 3 years ago

@ragavendranbala can you share the android implementation