-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_to_onnx.py
42 lines (39 loc) · 1.11 KB
/
convert_to_onnx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from transformers.convert_graph_to_onnx import convert
from pathlib import Path
from argparse import ArgumentParser
def parse_args():
parser = ArgumentParser(
prog="ConvertModelToOnnx",
description="Converts a model to ONNX"
)
parser.add_argument(
"-ip","--input-model-path",
type=str,
help="The path to the input modelpackage"
)
parser.add_argument(
"-if","--input-model-framework",
type=str,
help="The framework of the model in the package (IE \"pt\")"
)
parser.add_argument(
"-o","--output-path",
type=str,
help="The path to write the ONNX binary to"
)
parser.add_argument(
"-op","--opset",
type=str,
help="The path to write the ONNX binary to"
)
return parser.parse_args().__dict__
def main(input_model_framework: str,input_model_path,output_path,opset) -> None:
convert(
framework=input_model_framework,
model=input_model_path,
output=Path(output_path),
opset=opset
)
if __name__ == "__main__":
args = parse_args()
main(**args)