Package: sio4onnx
sio4onnxSimple tool to change the INPUT and OUTPUT shape of ONNX.https://github.com/PINTO0309/simple-onnx-processing-tools1. Setup1-1. HostPC### option$echoexportPATH="~/.local/bin:$PATH">>~/.bashrc\&&source~/.bashrc### run$pipinstall-Uonnx\&&pipinstall-Usio4onnx1-2. Dockerhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker2. CLI Usage$sio4onnx-h

usage:sio4onnx[-h]-ifINPUT_ONNX_FILE_PATH-ofOUTPUT_ONNX_FILE_PATH-iINPUT_NAMES-isINPUT_SHAPES[INPUT_SHAPES...]-oOUTPUT_NAMES-osOUTPUT_SHAPES[OUTPUT_SHAPES...][-n]optionalarguments:-h,--helpShowthishelpmessageandexit.-ifINPUT_ONNX_FILE_PATH,--input_onnx_file_pathINPUT_ONNX_FILE_PATHINPUTONNXfilepath-ofOUTPUT_ONNX_FILE_PATH,--output_onnx_file_pathOUTPUT_ONNX_FILE_PATHOUTPUTONNXfilepath-iINPUT_NAMES,--input_namesINPUT_NAMESListofinputOPnames.AllinputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforinput_shapes.e.g.--input_names"input.A"\--input_names"input.B"\--input_names"input.C"-isINPUT_SHAPES[INPUT_SHAPES...],--input_shapesINPUT_SHAPES[INPUT_SHAPES...]ListofinputOPshapes.AllinputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforinput_names.e.g.--input_shapes13"H""W"\--input_shapes"N"3"H""W"\--input_shapes"-1"3480640-oOUTPUT_NAMES,--output_namesOUTPUT_NAMESListofoutputOPnames.AlloutputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforoutput_shapes.e.g.--output_names"output.a"\--output_names"output.b"\--output_names"output.c"-osOUTPUT_SHAPES[OUTPUT_SHAPES...],--output_shapesOUTPUT_SHAPES[OUTPUT_SHAPES...]ListofinputOPshapes.AlloutputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforoutput_shapes.e.g.--output_shapes13"H""W"\--output_shapes"N",3,"H","W"\--output_shapes"-1"3480640-n,--non_verboseDonotshowallinformationlogs.Onlyerrorlogsaredisplayed.3. In-script Usage>>>fromsio4onnximportio_change>>>help(io_change)Helponfunctionio_changeinmodulesio4onnx.onnx_input_output_variable_changer:io_change(input_onnx_file_path:Union[str,NoneType]='',onnx_graph:Union[onnx.onnx_ml_pb2.ModelProto,NoneType]=None,output_onnx_file_path:Union[str,NoneType]='',input_names:Union[List[str],NoneType]=[],input_shapes:Union[List[Union[int,str]],NoneType]=[],output_names:Union[List[str],NoneType]=[],output_shapes:Union[List[Union[int,str]],NoneType]=[],non_verbose:Union[bool,NoneType]=False,)->onnx.onnx_ml_pb2.ModelProtoParameters----------input_onnx_file_path:Optional[str]Inputonnxfilepath.Eitherinput_onnx_file_pathoronnx_graphmustbespecified.Default:''onnx_graph:Optional[onnx.ModelProto]onnx.ModelProto.Eitherinput_onnx_file_pathoronnx_graphmustbespecified.onnx_graphIfspecified,ignoreinput_onnx_file_pathandprocessonnx_graph.output_onnx_file_path:Optional[str]Outputonnxfilepath.Ifnotspecified,noONNXfileisoutput.Default:''input_names:Optional[List[str]]ListofinputOPnames.AllinputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforinput_shapes.e.g.['input.A','input.B','input.C']input_shapes:Optional[List[Union[int,str]]]ListofinputOPshapes.AllinputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforinput_names.e.g.[[1,3,'H','W'],['N',3,'H','W'],['-1',3,480,640],]output_names:Optional[List[str]]ListofoutputOPnames.AlloutputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforoutput_shapes.e.g.['output.a','output.b','output.c']output_shapes:Optional[List[Union[int,str]]]ListofinputOPshapes.AlloutputOPsofthemodelmustbespecified.Theorderisunspecified,butmustmatchtheorderspecifiedforoutput_shapes.e.g.[[1,3,'H','W'],['N',3,'H','W'],['-1',3,480,640],]non_verbose:Optional[bool]Donotshowallinformationlogs.Onlyerrorlogsaredisplayed.Default:FalseReturns-------io_changed_graph:onnx.ModelProtoonnxModelProtowithmodifiedINPUTandOUTPUTshapes.4. CLI Execution$sio4onnx\--input_onnx_file_pathyolov3-10.onnx\--output_onnx_file_pathyolov3-10_upd.onnx\--input_names"input_1"\--input_names"image_shape"\--input_shapes"batch"3"H""W"\--input_shapes"batch"2\--output_names"yolonms_layer_1/ExpandDims_1:0"\--output_names"yolonms_layer_1/ExpandDims_3:0"\--output_names"yolonms_layer_1/concat_2:0"\--output_shapes1"boxes"4\--output_shapes1"classes""boxes"\--output_shapes"boxes"35. In-script Executionfromsio4onnximportio_changeestimated_graph=io_change(input_onnx_file_path="yolov3-10.onnx",output_onnx_file_path="yolov3-10_upd.onnx",input_names=["input_1","image_shape",],input_shapes=[["batch",3,"H","W"],["batch",2],],output_names=["yolonms_layer_1/ExpandDims_1:0","yolonms_layer_1/ExpandDims_3:0","yolonms_layer_1/concat_2:0",],output_shapes=[[1,"boxes",4],[1,"classes","boxes"],["boxes",3],],)6. SampleBeforeAfter