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