How to use the x2paddle.decoder.onnx_decoder.ONNXDecoder function in x2paddle

To help you get started, we’ve selected a few x2paddle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaddlePaddle / X2Paddle / x2paddle / convert.py View on Github external
def onnx2paddle(model_path, save_dir, params_merge=False):
    # check onnx installation and version
    try:
        import onnx
        version = onnx.version.version
        if version != '1.5.0':
            print("onnx==1.5.0 is required")
            return
    except:
        print("onnx is not installed, use \"pip install onnx==1.5.0\".")
        return
    print("Now translating model from onnx to paddle.")

    from x2paddle.decoder.onnx_decoder import ONNXDecoder
    model = ONNXDecoder(model_path)

    from x2paddle.op_mapper.onnx_op_mapper import ONNXOpMapper
    mapper = ONNXOpMapper(model, save_dir)

    from x2paddle.optimizer.onnx_optimizer import ONNXOptimizer
    optimizer = ONNXOptimizer(mapper)

    optimizer.delete_redundance_code()
    mapper.save_inference_model(save_dir, params_merge)