Run Converted .pb model by using OpenCV's DNN Module

asked 2020-01-13 03:16:26 -0500

FishCoder gravatar image

Hello, i have generated a .h5 model by using code. Then, i have converted the .h5 model to .pb by using code.

After that, to generate .pbtxt file, i am trying to use code. I am getting following error:

Traceback (most recent call last): File "", line 86, in <module> assert(graph_def.node[0].op == 'Placeholder') IndexError: list index out of range

I am getting same error, even if i create sorted_graph by using following code:

import tensorflow as tf
from import TransformGraph
with tf.gfile.FastGFile('C:/Users/Dell/Desktop/learnopencv-master/learnopencv-master/Mask-RCNN/IG/mask_frozen_graph.pb ', 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def = TransformGraph(graph_def, ['image_tensor'], ['detection_boxes', 'detection_classes', 'detection_scores', 
    'num_detections'], ['sort_by_execution_order'])
     with tf.gfile.FastGFile('sorted_mask_inference_graph.pb', 'wb') as f:


After i have tried all of these, i have tested with OpenCV's dnn module the generated .pb file with a previosly working .pbtxt file i am getting following error:

File "", line 108, in <module> net = cv.dnn.readNetFromTensorflow(modelWeights, textGraph); cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:1583: error: (-2:Unspecified error) Input layer not found: Preprocessor/mul/x in function 'cv::dnn::dnn4_v20190902::`anonymous-namespace'::TFImporter::populateNet'

graph.pbtxt is working .pbtxt file, mask_frozen_graph.pb is converted from mask_rcnn_signal_0040.h5 file, NucleusConfig.txt is configuration file that is used for training MatterPort's code, pipeline__.config is trying to use for generate .pbtxt with,

at the atteched Drive link:

I am waiting for your help. I want to run MatterPort's model with OpenCV dnn module. I do not want to use Tensorflow OD API, because I'm not sure to get as successful as the matterport's model and also I am not sure how should i create training folder structure.

edit retag flag offensive close merge delete


I do not want to use Tensorflow OD API

unfortunately, that's the only path which is guaranteed to work.

berak gravatar imageberak ( 2020-01-13 03:23:23 -0500 )edit

Thank you for your advice @berak. If you know, could you tell me how should i create a folder structure for instance segmentation in order to train by using Tensorflow OD API?

FishCoder gravatar imageFishCoder ( 2020-01-13 04:06:40 -0500 )edit

Hi, I trained my dataset by using TF OD API, but i could not get accuracy as good as MatterPort's model.

FishCoder gravatar imageFishCoder ( 2020-01-28 05:44:27 -0500 )edit

I can share config file and small part of my dataset in order to understand that any problem exists.

FishCoder gravatar imageFishCoder ( 2020-01-28 05:56:51 -0500 )edit