Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify RunONNXModel.py for pip install #2857

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions utils/RunONNXModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def check_non_negative(argname, value):
help="Path to a folder containing reference inputs and outputs stored in protobuf."
" If --verify=ref, inputs and outputs are reference data for verification",
)
data_group.add_argument(
"--inputs-from-arrays",
help="List of numpy arrays used as inputs for inference"
)
data_group.add_argument(
"--load-ref-from-numpy",
metavar="PATH",
Expand Down Expand Up @@ -730,6 +734,8 @@ def main():
inputs = read_input_from_refs(len(input_names), args.load_ref)
elif args.load_ref_from_numpy:
inputs = read_input_from_refs(len(input_names), args.load_ref_from_numpy)
elif args.inputs_from_arrays:
inputs = args.inputs_from_arrays
else:
inputs = generate_random_input(input_signature, input_shapes)

Expand Down Expand Up @@ -861,7 +867,19 @@ def main():
"using atol={}, rtol={} ...".format(args.atol, args.rtol),
)
verify_outs(outs[i], ref_outs[i])


return outs

# Python function inteface for RunONNXModel
# Arguments are passed as named parameters for the function
# Extra functionality is to directly pass a list of arrays as inference input
def onnxmlirrun(onnx_model=None, compiled_so=None, inputs=None):
if onnx_model :
args.model = onnx_model
if compiled_so :
args.load_so = compiled_so
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check if both onnx_model and compiled_so are not given?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, and maybe if none are given, an error?

if inputs :
args.inputs_from_arrays = inputs
return main()

if __name__ == "__main__":
main()
Loading