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

Functions

 extract_test_args (s)
 Managing paths for the artifacts required by the test.
 
 check_for_errors ()
 
 error_checked (func)
 

Variables

 parser = argparse.ArgumentParser()
 
 type
 
 str
 
 required
 
 args = parser.parse_args()
 
list contents = [line.rstrip() for line in f]
 
list eval_lines = [line for line in contents if line.startswith('eval(')]
 
list test_args = [extract_test_args(line) for line in eval_lines]
 
list test_models = [Path(args.artifact_dir) / f'{arg}.circle' for arg in test_args]
 
list input_data
 
list expected_output_data
 
 ffi = FFI()
 
 C = ffi.dlopen(args.lib_path)
 
 Interpreter_new = error_checked(C.Interpreter_new)
 
 Interpreter_delete = error_checked(C.Interpreter_delete)
 
 Interpreter_interpret = error_checked(C.Interpreter_interpret)
 
 Interpreter_writeInputTensor = error_checked(C.Interpreter_writeInputTensor)
 
 Interpreter_readOutputTensor = error_checked(C.Interpreter_readOutputTensor)
 
 model_data = ffi.from_buffer(bytearray(f.read()))
 
 intp = Interpreter_new(model_data, len(model_data))
 
 h5 = h5py.File(input_data[idx])
 
 input_values = h5.get('value')
 
 input_num = len(input_values)
 
 arr = np.array(input_values.get(str(input_idx)))
 
 c_arr = ffi.from_buffer(arr)
 
 output_values = h5.get('value')
 
 output_num = len(output_values)
 
 result = np.empty(arr.shape, dtype=arr.dtype)
 

Function Documentation

◆ check_for_errors()

infer.check_for_errors ( )

Definition at line 55 of file infer.py.

55def check_for_errors():
56 error_message = ffi.string(C.get_last_error()).decode('utf-8')
57 if error_message:
58 C.clear_last_error()
59 raise RuntimeError(f'C++ Exception: {error_message}')
60
61

Referenced by error_checked().

◆ error_checked()

infer.error_checked (   func)
Decorator to wrap functions with error checking.

Definition at line 62 of file infer.py.

62def error_checked(func):
63 """
64 Decorator to wrap functions with error checking.
65 """
66 def wrapper(*args, **kwargs):
67 result = func(*args, **kwargs)
68 check_for_errors()
69 return result
70
71 return wrapper
72
73

References check_for_errors().

◆ extract_test_args()

infer.extract_test_args (   s)

Managing paths for the artifacts required by the test.

Definition at line 11 of file infer.py.

11def extract_test_args(s):
12 p = re.compile('eval\\((.*)\\)')
13 result = p.search(s)
14 return result.group(1)
15
16

Variable Documentation

◆ args

infer.args = parser.parse_args()

Definition at line 21 of file infer.py.

◆ arr

infer.arr = np.array(input_values.get(str(input_idx)))

Definition at line 92 of file infer.py.

◆ C

infer.C = ffi.dlopen(args.lib_path)

Definition at line 52 of file infer.py.

◆ c_arr

infer.c_arr = ffi.from_buffer(arr)

Definition at line 93 of file infer.py.

◆ contents

list infer.contents = [line.rstrip() for line in f]

Definition at line 24 of file infer.py.

◆ eval_lines

list infer.eval_lines = [line for line in contents if line.startswith('eval(')]

Definition at line 26 of file infer.py.

◆ expected_output_data

list infer.expected_output_data
Initial value:
1= [
2 Path(args.artifact_dir) / f'{arg}.opt/metadata/tc/expected.h5' for arg in test_args
3]

Definition at line 32 of file infer.py.

◆ ffi

infer.ffi = FFI()

Definition at line 40 of file infer.py.

◆ h5

infer.h5 = h5py.File(input_data[idx])

Definition at line 88 of file infer.py.

◆ input_data

list infer.input_data
Initial value:
1= [
2 Path(args.artifact_dir) / f'{arg}.opt/metadata/tc/input.h5' for arg in test_args
3]

Definition at line 29 of file infer.py.

◆ input_num

infer.input_num = len(input_values)

Definition at line 90 of file infer.py.

◆ input_values

infer.input_values = h5.get('value')

Definition at line 89 of file infer.py.

◆ Interpreter_delete

infer.Interpreter_delete = error_checked(C.Interpreter_delete)

Definition at line 75 of file infer.py.

◆ Interpreter_interpret

infer.Interpreter_interpret = error_checked(C.Interpreter_interpret)

Definition at line 76 of file infer.py.

◆ Interpreter_new

infer.Interpreter_new = error_checked(C.Interpreter_new)

Definition at line 74 of file infer.py.

◆ Interpreter_readOutputTensor

infer.Interpreter_readOutputTensor = error_checked(C.Interpreter_readOutputTensor)

Definition at line 78 of file infer.py.

◆ Interpreter_writeInputTensor

infer.Interpreter_writeInputTensor = error_checked(C.Interpreter_writeInputTensor)

Definition at line 77 of file infer.py.

◆ intp

infer.intp = Interpreter_new(model_data, len(model_data))

Definition at line 85 of file infer.py.

◆ model_data

infer.model_data = ffi.from_buffer(bytearray(f.read()))

Definition at line 82 of file infer.py.

◆ output_num

infer.output_num = len(output_values)

Definition at line 100 of file infer.py.

◆ output_values

infer.output_values = h5.get('value')

Definition at line 99 of file infer.py.

◆ parser

infer.parser = argparse.ArgumentParser()

Definition at line 17 of file infer.py.

◆ required

infer.required

Definition at line 18 of file infer.py.

◆ result

infer.result = np.empty(arr.shape, dtype=arr.dtype)

Definition at line 103 of file infer.py.

◆ str

infer.str

Definition at line 18 of file infer.py.

◆ test_args

list infer.test_args = [extract_test_args(line) for line in eval_lines]

Definition at line 27 of file infer.py.

◆ test_models

list infer.test_models = [Path(args.artifact_dir) / f'{arg}.circle' for arg in test_args]

Definition at line 28 of file infer.py.

◆ type

infer.type

Definition at line 18 of file infer.py.