How to use the x2paddle.op_mapper.onnx_op_mapper.ONNXOpMapper 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
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)
github PaddlePaddle / X2Paddle / x2paddle / op_mapper / onnx_op_mapper.py View on Github external
def __init__(self, decoder, save_dir):
        super(ONNXOpMapper, self).__init__()
        self.decoder = decoder
        self.graph = decoder.onnx_graph
        self.input_shapes = []
        self.weights = dict()
        self.omit_nodes = list()
        self.used_custom_layers = dict()
        self.is_inference = False
        self.tmp_data_dir = os.path.join(save_dir, 'tmp_data')
        self.get_output_shapes()

        if not self.op_checker():
            raise Exception("Model are not supported yet.")

        #mapping op
        print("Total nodes: {}".format(
            sum([