Could not convert Tensorflow Freeze Model for OpenCV Dnn 4.5.0-dev

Hey, I’m trying the popular deep sort market1501.pb model to use with opencv dnn.
I was not yet successful in doing that.

I’m using Opencv 4.5.0 dev, and tensorflow 2.4.0.

The steps I followed:

  1. Optimized the freeze model for inference.
  2. Removed const nodes and weights and saved as text representation.
  3. Replace and remove problematic subgraph without trying to break node.
    4 . Launced using opencvDnn

Step1

!python /tensorflow/python/tools/optimize_for_inference.py \
--input=/model_data/market1501.pb \
--output=optimized_graph.pb \
--frozen_graph=True \
--input_names=images \
--output_names=features

Step 2-

import tensorflow.compat.v1 as tf

Read the graph.

with tf.gfile.GFile(‘optimized_graph.pb’, ‘rb’) as f:

graph_def = tf.GraphDef()

graph_def.ParseFromString(f.read())

Remove Const nodes.

for i in reversed(range(len(graph_def.node))):

if graph_def.node[i].op == 'Const':

    del graph_def.node[i]

for attr in ['T', 'data_format', 'Tshape', 'N', 'Tidx', 'Tdim',

             'use_cudnn_on_gpu', 'Index', 'Tperm', 'is_training',

             'Tpaddings']:

    if attr in graph_def.node[i].attr:

        del graph_def.node[i].attr[attr]

Save as text.

tf.train.write_graph(graph_def, “”, “market1501.pbtxt”, as_text=True)

Step3:

changed market1501.pbtxt to market.pbtxt after replacing subgraphs.

Step4:

dsNet = cv2.dnn.readNetFromTensorflow(‘tensorflow-yolo/model_data/market1501.pb’, ‘market.pbtxt’)


error Traceback (most recent call last)
in ()
----> 1 dsNet = cv2.dnn.readNetFromTensorflow(‘tensorflow-yolo/model_data/market1501.pb’, ‘market.pbtxt’)

error: OpenCV(4.5.0-dev) /content/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:586: error: (-2:Unspecified error) Const input blob for weights not found in function 'getConstBlob'

How to get it working?