ONE - On-device Neural Engine
Loading...
Searching...
No Matches
dynamic_shape_inference Namespace Reference

Functions

 main (nnpackage_path, backends="cpu")
 

Variables

 argv = sys.argv[1:]
 

Function Documentation

◆ main()

dynamic_shape_inference.main (   nnpackage_path,
  backends = "cpu" 
)

Definition at line 7 of file dynamic_shape_inference.py.

7def main(nnpackage_path, backends="cpu"):
8 # Create session and load nnpackage
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
14 # Call infer() 10 times
15 for i in range(10):
16 dummy_inputs = []
17 for info in input_infos:
18 # Retrieve the dimensions list from tensorinfo property.
19 dims = list(info.dims)
20 # Replace -1 with a random value between 1 and 10
21 dims = [random.randint(1, 10) if d == -1 else d for d in dims]
22 # Build the shape tuple from tensorinfo dimensions.
23 shape = tuple(dims[:info.rank])
24 # Create a dummy numpy array filled with uniform random values in [0,1).
25 dummy_inputs.append(
26 np.random.uniform(low=0.0, high=1.0, size=shape).astype(info.dtype))
27
28 outputs = session.infer(dummy_inputs)
29 print(f"Inference run {i+1}/10 completed.")
30
31 print(f"nnpackage {nnpackage_path.split('/')[-1]} runs successfully.")
32 return
33
34
int main(void)

Variable Documentation

◆ argv

dynamic_shape_inference.argv = sys.argv[1:]

Definition at line 36 of file dynamic_shape_inference.py.