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

Functions

 chunks (lst, n)
 
 toNumpyType (circle_type)
 

Variables

 parser = argparse.ArgumentParser()
 
 type
 
 required
 
 help
 
 nargs
 
 action
 
 str
 
 default
 
 args = parser.parse_args()
 
 output_dir = args.output_dir
 
 artifact_dir = args.artifact_dir
 
 input_dir = args.input_dir
 
 test_param = args.test_param
 
 config = args.config
 
 mode = args.mode
 
dict modes_to_input_h5_suffix
 
 test_params = test_param[0].split()
 
int PARAM_SET_SIZE = 3
 
 model_name = test_params[idx][0]
 
 granularity = test_params[idx][1]
 
 dtype = test_params[idx][2]
 
 model = os.path.join(artifact_dir, model_name + '.circle')
 
 buf = f.read()
 
 circle_model = Model.GetRootAsModel(buf, 0)
 
 graph = circle_model.Subgraphs(0)
 
 inputs = graph.InputsAsNumpy()
 
str testcase = f'{model_name}.{granularity}.{dtype}'
 
 output = os.path.join(output_dir, f'{testcase}.{modes_to_input_h5_suffix[mode]}')
 
 h5_file = h5.File(output, 'w')
 
 group = h5_file.create_group("value")
 
 input_text_dir
 
 records = sorted(glob.glob(input_text_dir + "/*.txt"))
 
 sample = group.create_group(str(i))
 
 lines = f.readlines()
 
 data = np.array(line.split(','))
 
 input_index = inputs[j]
 
 tensor = graph.Tensors(input_index)
 
 np_type = toNumpyType(tensor.Type())
 
 input_data = np.array(data.reshape(tensor.ShapeAsNumpy()), np_type)
 

Function Documentation

◆ chunks()

gen_h5_explicit_inputs_all.chunks (   lst,
  n 
)
Yield successive n-sized chunks from the list

Definition at line 11 of file gen_h5_explicit_inputs_all.py.

11def chunks(lst, n):
12 """Yield successive n-sized chunks from the list"""
13 for i in range(0, len(lst), n):
14 yield lst[i:i + n]
15
16

◆ toNumpyType()

gen_h5_explicit_inputs_all.toNumpyType (   circle_type)

Definition at line 17 of file gen_h5_explicit_inputs_all.py.

17def toNumpyType(circle_type):
18 if circle_type == TensorType.UINT8:
19 return np.uint8
20 if circle_type == TensorType.FLOAT32:
21 return np.float32
22 if circle_type == TensorType.INT16:
23 return np.int16
24
25
26#
27# This script generates a pack of random input data (.h5) expected by the input circle models
28#
29# The input directory should be organized as follows
30# <input_directory>/
31# -> <record_index>.txt
32# ...
33# Each txt file has the explicit values of inputs
34# Example. if the model has two inputs whose shapes are both (1, 3),
35# the first record file name is 0.txt, and its contents is something like below
36# 1, 2, 3
37# 4, 5, 6
38#

Variable Documentation

◆ action

gen_h5_explicit_inputs_all.action

Definition at line 60 of file gen_h5_explicit_inputs_all.py.

◆ args

gen_h5_explicit_inputs_all.args = parser.parse_args()

Definition at line 62 of file gen_h5_explicit_inputs_all.py.

◆ artifact_dir

gen_h5_explicit_inputs_all.artifact_dir = args.artifact_dir

Definition at line 65 of file gen_h5_explicit_inputs_all.py.

◆ buf

gen_h5_explicit_inputs_all.buf = f.read()

Definition at line 87 of file gen_h5_explicit_inputs_all.py.

◆ circle_model

gen_h5_explicit_inputs_all.circle_model = Model.GetRootAsModel(buf, 0)

Definition at line 88 of file gen_h5_explicit_inputs_all.py.

◆ config

gen_h5_explicit_inputs_all.config = args.config

Definition at line 68 of file gen_h5_explicit_inputs_all.py.

◆ data

gen_h5_explicit_inputs_all.data = np.array(line.split(','))

Definition at line 116 of file gen_h5_explicit_inputs_all.py.

◆ default

gen_h5_explicit_inputs_all.default

Definition at line 61 of file gen_h5_explicit_inputs_all.py.

◆ dtype

gen_h5_explicit_inputs_all.dtype ( void  ) = test_params[idx][2]

Definition at line 83 of file gen_h5_explicit_inputs_all.py.

◆ granularity

gen_h5_explicit_inputs_all.granularity = test_params[idx][1]

Definition at line 82 of file gen_h5_explicit_inputs_all.py.

◆ graph

gen_h5_explicit_inputs_all.graph = circle_model.Subgraphs(0)

Definition at line 92 of file gen_h5_explicit_inputs_all.py.

◆ group

gen_h5_explicit_inputs_all.group = h5_file.create_group("value")

Definition at line 100 of file gen_h5_explicit_inputs_all.py.

◆ h5_file

gen_h5_explicit_inputs_all.h5_file = h5.File(output, 'w')

Definition at line 99 of file gen_h5_explicit_inputs_all.py.

◆ help

gen_h5_explicit_inputs_all.help

Definition at line 43 of file gen_h5_explicit_inputs_all.py.

◆ input_data

gen_h5_explicit_inputs_all.input_data = np.array(data.reshape(tensor.ShapeAsNumpy()), np_type)

Definition at line 120 of file gen_h5_explicit_inputs_all.py.

◆ input_dir

gen_h5_explicit_inputs_all.input_dir = args.input_dir

Definition at line 66 of file gen_h5_explicit_inputs_all.py.

◆ input_index

gen_h5_explicit_inputs_all.input_index = inputs[j]

Definition at line 117 of file gen_h5_explicit_inputs_all.py.

◆ input_text_dir

gen_h5_explicit_inputs_all.input_text_dir
Initial value:
1= os.path.join(input_dir,
2 f'{model_name}_config/{granularity}/{dtype}')

Definition at line 104 of file gen_h5_explicit_inputs_all.py.

◆ inputs

gen_h5_explicit_inputs_all.inputs = graph.InputsAsNumpy()

Definition at line 93 of file gen_h5_explicit_inputs_all.py.

◆ lines

gen_h5_explicit_inputs_all.lines = f.readlines()

Definition at line 114 of file gen_h5_explicit_inputs_all.py.

◆ mode

gen_h5_explicit_inputs_all.mode = args.mode

Definition at line 69 of file gen_h5_explicit_inputs_all.py.

◆ model

gen_h5_explicit_inputs_all.model = os.path.join(artifact_dir, model_name + '.circle')

Definition at line 85 of file gen_h5_explicit_inputs_all.py.

◆ model_name

gen_h5_explicit_inputs_all.model_name = test_params[idx][0]

Definition at line 81 of file gen_h5_explicit_inputs_all.py.

◆ modes_to_input_h5_suffix

dict gen_h5_explicit_inputs_all.modes_to_input_h5_suffix
Initial value:
1= {
2 'default': 'input.h5',
3 'mixed_quantization': 'mixed.input.h5',
4}

Definition at line 71 of file gen_h5_explicit_inputs_all.py.

◆ nargs

gen_h5_explicit_inputs_all.nargs

Definition at line 56 of file gen_h5_explicit_inputs_all.py.

◆ np_type

gen_h5_explicit_inputs_all.np_type = toNumpyType(tensor.Type())

Definition at line 119 of file gen_h5_explicit_inputs_all.py.

◆ output

gen_h5_explicit_inputs_all.output = os.path.join(output_dir, f'{testcase}.{modes_to_input_h5_suffix[mode]}')

Definition at line 96 of file gen_h5_explicit_inputs_all.py.

◆ output_dir

gen_h5_explicit_inputs_all.output_dir = args.output_dir

Definition at line 64 of file gen_h5_explicit_inputs_all.py.

◆ PARAM_SET_SIZE

int gen_h5_explicit_inputs_all.PARAM_SET_SIZE = 3

Definition at line 77 of file gen_h5_explicit_inputs_all.py.

◆ parser

gen_h5_explicit_inputs_all.parser = argparse.ArgumentParser()

Definition at line 39 of file gen_h5_explicit_inputs_all.py.

◆ records

gen_h5_explicit_inputs_all.records = sorted(glob.glob(input_text_dir + "/*.txt"))

Definition at line 109 of file gen_h5_explicit_inputs_all.py.

◆ required

gen_h5_explicit_inputs_all.required

Definition at line 42 of file gen_h5_explicit_inputs_all.py.

◆ sample

gen_h5_explicit_inputs_all.sample = group.create_group(str(i))

Definition at line 111 of file gen_h5_explicit_inputs_all.py.

◆ str

gen_h5_explicit_inputs_all.str

Definition at line 61 of file gen_h5_explicit_inputs_all.py.

◆ tensor

gen_h5_explicit_inputs_all.tensor = graph.Tensors(input_index)

Definition at line 118 of file gen_h5_explicit_inputs_all.py.

◆ test_param

gen_h5_explicit_inputs_all.test_param = args.test_param

Definition at line 67 of file gen_h5_explicit_inputs_all.py.

◆ test_params

gen_h5_explicit_inputs_all.test_params = test_param[0].split()

Definition at line 76 of file gen_h5_explicit_inputs_all.py.

◆ testcase

str gen_h5_explicit_inputs_all.testcase = f'{model_name}.{granularity}.{dtype}'

Definition at line 95 of file gen_h5_explicit_inputs_all.py.

◆ type

gen_h5_explicit_inputs_all.type

Definition at line 41 of file gen_h5_explicit_inputs_all.py.