Git Product home page Git Product logo

Comments (2)

Mauro-Antonello avatar Mauro-Antonello commented on June 10, 2024 1

Hi, I was facing the same problem and solved by wrapping the prediction decoding to the model outputs and, finally, converting the wrapped model.

from keras_cv.src.models.object_detection.yolo_v8.yolo_v8_detector import YOLOV8Detector, decode_regression_to_boxes, dist2bbox, get_anchors
def convert_to_onnx(model: YOLOV8Detector, onnx_opset: int, results_dir: Path):
    wrapper_input = tf.keras.Input(shape=model.input_shape[1:], name="images")
    wrapper_outputs = model(wrapper_input)
    anchor_points, stride_tensor = get_anchors(image_shape=model.input_shape[1:3])
    stride_tensor = tf.expand_dims(stride_tensor, axis=-1)
    boxes = dist2bbox(decode_regression_to_boxes(wrapper_outputs["boxes"]), anchor_points) * stride_tensor
    wrapper_outputs["boxes"] = boxes
    wrapper = tf.keras.Model(wrapper_input, wrapper_outputs, name="YOLOv8")
    tf2onnx.convert.from_keras(wrapper, output_path=results_dir / "model.onnx", opset=onnx_opset)

from tensorflow-onnx.

fatcat-z avatar fatcat-z commented on June 10, 2024

@ksv87 ,

I think there are 2 issues you are facing when convert the model to an ONNX one:

  1. The outputs without decode_prediction are not expected. Actually @Mauro-Antonello has provided a popular approach to handle such case: add a wrapped model so the outputs of your model are intermediate results.
  2. There is an unsupported op BroadcastArgs in your model. This will cause the final ONNX model could not be inferenced by ORT successfully. This needs some work in tf2onnx to support and it is not in a plan yet. But your contributions on this are definitely welcome!

from tensorflow-onnx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.