Ask Your Question

Revision history [back]

Converting keras model to opencv. Problem with flatten layer.

Opencv version: 4.1.0 (using opencv plugin for unity)

Operating system: Windows 10

I'm trying to port to Unity keras model that detect emotions from human faces I'm using Unity opencv plugin that has already example that detects face from picture, so all I have to do is feed the square with face to the deep neural network.

I've tried converting the model to pb file using this (https://github.com/amir-abdi/keras_to_tensorflow) but after plugging it to the program I got errors like:

dnn::forward_11() : OpenCV(4.1.0-dev) C:\Users\satoo\Desktop\opencv\modules\dnn\src\dnn.cpp:524: error: (-2:Unspecified error) Can't create layer "flatten_1/Shape" of type "Shape" in function 'cv::dnn::dnn4_v20190122::LayerData::getLayerInstance'

I've tried using script to remove incompatible nodes, but it looks like it makes incorrect network. I couldn't make the updated network work neither in unity nor original python program.

Finally I've tried removing nodes manually from the graph following instructions from here and here but it doesn't work. Trying to load the network from pb model and pbtext file results in Unity just crashing - it most likely means that it fails to load the network from files.

Is there a way to remove incompatible nodes from the network? Preferrably not manually.