Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frozen graph #38

Open
fisakhan opened this issue Oct 26, 2021 · 0 comments
Open

frozen graph #38

fisakhan opened this issue Oct 26, 2021 · 0 comments

Comments

@fisakhan
Copy link

I converted the retinaface savedmodel format to frozen graph by executing the following code:

import tensorflow as tf
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2

path2savedmodel = './tf-serving-retinaface_mbv2/1'
path2frozengraph = './models/retinaface.pb'
loaded = tf.saved_model.load(path2savedmodel)
infer = loaded.signatures['serving_default']
f = tf.function(infer).get_concrete_function(input_image=tf.TensorSpec(shape=[None, None, None, 3], dtype=tf.float32))
f2 = convert_variables_to_constants_v2(f)
graph_def = f2.graph.as_graph_def()# Export frozen graph
# write frozen graph (single file) to disk
with tf.io.gfile.GFile(path2frozengraph, 'wb') as f:
   f.write(graph_def.SerializeToString())

While loading the frozen graph in opencv using the following code

print('\n\nloading frozen model...')
net = cv2.dnn.readNet(path2frozengraph)
#net_tf = cv2.dnn.readNetFromTensorflow(path2frozengraph)

I get the following errro

[ERROR:0] global /tmp/pip-req-build-tjxnaiom/opencv/modules/dnn/src/tensorflow/tf_importer.cpp (2804) parseNode DNN/TF: Can't parse layer for node='StatefulPartitionedCall/StatefulPartitionedCall/RetinaFaceModel/ClassHead_2/mul_1' of type='Mul'. Exception: OpenCV(4.5.3) /tmp/pip-req-build-tjxnaiom/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:1464: error: (-215:Assertion failed) scaleMat.type() == CV_32FC1 in function 'parseMul'

Traceback (most recent call last):
  File "/home/Projects/bitbucket/model_conversion/use_retinaface_pb_in_cv2.py", line 188, in <module>
    net = cv2.dnn.readNet(path2frozengraph)

error: OpenCV(4.5.3) /tmp/pip-req-build-tjxnaiom/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:1464: error: (-215:Assertion failed) scaleMat.type() == CV_32FC1 in function 'parseMul'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant