ONE - On-device Neural Engine
Loading...
Searching...
No Matches
minimal.py
Go to the documentation of this file.
1from onert import infer
2import numpy as np
3import sys
4
5
6def main(nnpackage_path, backends="cpu"):
7 # Create session and load nnpackage
8 # The default value of backends is "cpu".
9 session = infer.session(nnpackage_path, backends)
10
11 # Prepare input. Here we just allocate dummy input arrays.
12 input_infos = session.get_inputs_tensorinfo()
13 dummy_inputs = []
14 for info in input_infos:
15 # Retrieve the dimensions list from tensorinfo property.
16 dims = list(info.dims)
17 # Build the shape tuple from tensorinfo dimensions.
18 shape = tuple(dims[:info.rank])
19 # Create a dummy numpy array filled with zeros.
20 dummy_inputs.append(np.zeros(shape, dtype=info.dtype))
21
22 outputs = session.infer(dummy_inputs)
23
24 print(f"nnpackage {nnpackage_path.split('/')[-1]} runs successfully.")
25 return
26
27
28if __name__ == "__main__":
29 argv = sys.argv[1:]
30 main(*argv)
int main(void)