using keras_cv model in opencv is possible?

78 views Asked by At

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

0

There are 0 answers