You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
model = tf.keras.models.load_model(os.path.join(path, file))
Convert Keras model to ConcreteFunction full_model = tf.function(lambda x: model(x)) full_model = full_model.get_concrete_function( tf.TensorSpec(model.inputs[0].shape, model.inputs[0].dtype))
Get frozen ConcreteFunction frozen_func = convert_variables_to_constants_v2(full_model) frozen_func.graph.as_graph_def()
Save frozen graph from frozen ConcreteFunction to hard drive tf.io.write_graph(graph_or_graph_def=frozen_func.graph, logdir=path_res, name=file.split('.')[0]+".pb", as_text=False)
and recive error:[ERROR:[email protected]] global tf_importer.cpp:3171 parseNode DNN/TF: Can't parse layer for node='yolov8_detector_2/tf.repeat_11/Repeat/Reshape' of type='Reshape'. Exception: OpenCV(4.8.1) /io/opencv/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp:902: error: (-215:Assertion failed) !field.empty() in function 'getTensorContentRef_'
What i do wrong?
P.s.: i completely did this way with classification keras model, but with keras_cv objectdetection model i cannot do this... Please help me!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I trained object detection model in keras_cv like this https://keras.io/examples/vision/retinanet and like this https://keras.io/examples/vision/yolov8.
Next i converted model to frozen graph like this
model = tf.keras.models.load_model(os.path.join(path, file))
Convert Keras model to ConcreteFunction
full_model = tf.function(lambda x: model(x)) full_model = full_model.get_concrete_function( tf.TensorSpec(model.inputs[0].shape, model.inputs[0].dtype))
Get frozen ConcreteFunction
frozen_func = convert_variables_to_constants_v2(full_model) frozen_func.graph.as_graph_def()
Save frozen graph from frozen ConcreteFunction to hard drive
tf.io.write_graph(graph_or_graph_def=frozen_func.graph, logdir=path_res, name=file.split('.')[0]+".pb", as_text=False)
I try load this frozen graph like this
tensorflowNet = cv2.dnn.readNetFromTensorflow('model.pb')
and recive error:
[ERROR:[email protected]] global tf_importer.cpp:3171 parseNode DNN/TF: Can't parse layer for node='yolov8_detector_2/tf.repeat_11/Repeat/Reshape' of type='Reshape'. Exception: OpenCV(4.8.1) /io/opencv/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp:902: error: (-215:Assertion failed) !field.empty() in function 'getTensorContentRef_'
What i do wrong?
P.s.: i completely did this way with classification keras model, but with keras_cv objectdetection model i cannot do this... Please help me!
I try find example in google
Beta Was this translation helpful? Give feedback.
All reactions