Package: sed4onnx
sed4onnxSimple ONNX constant encoder/decoder.https://github.com/PINTO0309/simple-onnx-processing-toolsKey conceptSince the constant values in the JSON files generated byonnx2jsonare Base64-encoded values, ASCII <-> Base64 conversion is required when rewriting JSON constant values.After writing the converted Base64 strings to JSON using this tool,json2onnxcan be used to regenerate the constant-modified ONNX file.1. Setup1-1. HostPC### option$echoexportPATH="~/.local/bin:$PATH">>~/.bashrc\&&source~/.bashrc### run$pipinstall-Used4onnx1-2. Dockerhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker2. CLI Usage$ sed4onnx -h

usage:
    sed4onnx [-h]
    -cs CONSTANT_STRING
    [-d {float16,float32,float64,uint8,int8,int16,int32,int64,string}]
    [-m {encode,decode}]

optional arguments:
  -h, --help
        show this help message and exit.

  -cs CONSTANT_STRING, --constant_string CONSTANT_STRING
        Strings to be encoded and decoded for ONNX constants.

  -d {float16,float32,float64,uint8,int8,int16,int32,int64,string}, \
    --dtype {float16,float32,float64,uint8,int8,int16,int32,int64,string}
        Data type.

  -m {encode,decode}, --mode {encode,decode}
        encode: Converts the string specified in constant_string to a Base64 format string
                that can be embedded in ONNX constants.
        decode: Converts a Base64 string specified in constant_string to ASCII like
                Numpy string or pure string.3. In-script Usage>>>fromsed4onnximportencode>>>fromsed4onnximportdecode>>>help(encode)Helponfunctionencodeinmodulesed4onnx.onnx_constant_encoder_decoder:encode(constant_string:str)->strParameters----------constant_string:strASCIIstringtobeencoded.dtype:str'float16'or'float32'or'float64'or'uint8'or'int8'or'int16'or'int32'or'int64'or'string'Returns-------encoded_string:strBase64-encodedASCIIstring.>>>help(decode)Helponfunctiondecodeinmodulesed4onnx.onnx_constant_encoder_decoder:decode(constant_string:str,dtype:str)->numpy.ndarrayParameters----------constant_string:strBase64stringtobedecoded.dtype:str'float16'or'float32'or'float64'or'uint8'or'int8'or'int16'or'int32'or'int64'or'string'Returns-------decoded_ndarray:np.ndarrayBase64-decodednumpy.ndarray.4. CLI Execution$sed4onnx\--constant_string[-1,3,224,224]\--dtypeint64\--modeencode

$sed4onnx\--constant_string'//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA='\--dtypeint64\--modedecode5. In-script Executionfromsed4onnximportencodefromsed4onnximportdecodebase64_string=encode(constant_string='[-1,3,224,224]',dtype='int64',)numpy_ndarray=decode(constant_string='//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=',dtype='int64',)6. Sample$sed4onnx\--constant_string[-1,3,224,224]\--dtypeint64\--modeencode

//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA=$sed4onnx\--constant_string'//////////8DAAAAAAAAAOAAAAAAAAAA4AAAAAAAAAA='\--dtypeint64\--modedecode[-1,3,224,224]7. Referencehttps://github.com/onnx/onnx/blob/main/docs/Operators.mdhttps://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.htmlhttps://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeonhttps://github.com/PINTO0309/simple-onnx-processing-toolshttps://github.com/PINTO0309/PINTO_model_zoo8. Issueshttps://github.com/PINTO0309/simple-onnx-processing-tools/issues