GithubHelp home page GithubHelp logo

Comments (7)

paulgavrikov avatar paulgavrikov commented on May 22, 2024

It would be awesome if you could implement this! Unfortunately, the mediapipe models often rely on fp16 weights.

from tflite2onnx.

ram95014 avatar ram95014 commented on May 22, 2024

I would second @paulgavrikov and request the fold from fp16 to fp32. Thanks. If that is not possible or would take a long time, it would be great if you can guide me to do this.

from tflite2onnx.

zhenhuaw-me avatar zhenhuaw-me commented on May 22, 2024

@paulgavrikov @ram95014 Thanks for your feedback! I am very glad about that. This should be possible and should not take too much time but I was not working on it. It would be great if you can help!

In general, it could be divided into three steps:

  1. Parse and build the graph just like ONNX can support FP16 as a quantization type. In this stage, we will have many patterns like FP16 weights -> Dequantize -> FP32 Tensor -> Conv/MatMul which will become illegal if convert to ONNX directly. I think we can support this stage currently but I have not tried that locally.
  2. Walk the graph and fold FP16 weights. We can introduce a new pass like layout propagation or handling quantization - may be name like foldFP16Weights. Search the FP16 weights -> Dequantize -> FP32 Tensor -> Conv/MatMul in the graph (iterate the operators and check), for each pattern P:
    1. Cast the weights of the FP16 weights to FP32 directly, including changing Tensor.data, Tensor.dtype and etc.
    2. Detach the FP16 weights (which are actually FP32 weights now) and the Dequantize operator, and the FP32 Tensor and the Conv/MatMul operator.
    3. Attach the casted FP16 weights (which are actually FP32 weights now) to the Conv/MatMul operator.
    4. Remove the Dequantize and FP32 Tensor from the graph.
  3. Recollect the tensors and operator like other graph operator passes.

I would suggest starting by adding a new operator to tflite2onnx to understand the code. They are pretty easy, you may find some in merged PRs.

It would be great if we can bring it up in the next minor release. Let's prioritize it!

from tflite2onnx.

zhenhuaw-me avatar zhenhuaw-me commented on May 22, 2024

@paulgavrikov @ram95014 This functionality has been enabled, please try out with the latest code.
If anything looks wrong, please open issues and link to this one. Thanks!

from tflite2onnx.

mikkelmedm avatar mikkelmedm commented on May 22, 2024

Hi, should this be fixed? I am still having issues

from tflite2onnx.

zhenhuaw-me avatar zhenhuaw-me commented on May 22, 2024

@mikkelmedm It has been fixed and protected by this test. What's the error you have?

from tflite2onnx.

mikkelmedm avatar mikkelmedm commented on May 22, 2024

Running it on a MediaPipe model I am getting an error like "FP16 is not tested, and might not work properly"

from tflite2onnx.

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.