OpenCVForUnity icon indicating copy to clipboard operation
OpenCVForUnity copied to clipboard

DNN module crash when using a custom TensorFlow model

Open Kasidit0052 opened this issue 5 years ago • 2 comments

Hello, I'm trying to integrate my custom TensorFlow model to OpenCVForUnity DNN modules but the Unity editor crash. I have already trained my model using Keras and convert the model to .pb. However, the unity editor crash when I copy protobuf file and create a tag.txt in Assets/StreamingAssets/dnn. If the problem can be solved, could you please elaborate the solution for me.

I'm going to give the model file because it might be helpful. tensorflow_inception_graph.zip

thank you very much

Kasidit0052 avatar Aug 15 '20 06:08 Kasidit0052

Thank you for your inquiry.

Unfortunately, I don't know much about the Deep learning and Tensorflow models. In order to read the pb file with OpenCV, it seems that it is necessary to convert it for OpenCV. https://stackoverflow.com/questions/60625128/importing-automl-edge-train-model-in-opencv https://github.com/opencv/opencv/wiki/TensorFlow-text-graphs https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API

EnoxSoftware avatar Aug 15 '20 08:08 EnoxSoftware

Thank you for your response, It's seems like we need to freeze the model into a single inference graph before passing it to OpenCV DNN otherwise the Unity Editor will crash. This might be a problem in OpenCV itself.

Freezing Graph in TensorFlow 2.0 is quite difficult so I'm going to place the solution here in case someone have same problem https://github.com/leimao/Frozen_Graph_TensorFlow

Kasidit0052 avatar Aug 17 '20 02:08 Kasidit0052