ONE - On-device Neural Engine
Loading...
Searching...
No Matches
common_place.py
Go to the documentation of this file.
1import h5py
2import argparse
3from argparse import RawTextHelpFormatter
4
5
7 """
8 This function is intended to decompose the necessary steps to obtain information from the command line.
9
10 :return: argparse object, which hold paths to nn model and input data
11 """
12 parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
13
14 parser.add_argument('-m',
15 '--model',
16 help=("specify input file with NN model, \n[depends from model, "
17 " two for caffe and caffe2, one for onnx and tflite]"),
18 nargs='+')
19 parser.add_argument('-i',
20 '--input',
21 help=(" specify file with neural"
22 " network input data, hdf5 for caffe caffe2 tflite "
23 "and pb for onnx"),
24 required=True)
25 parser.add_argument(
26 '-o',
27 '--output_path',
28 help='here you specify which place will hold your output, default here',
29 default='')
30
31 args = parser.parse_args()
32 # added to check is our input file or not. most simple way
33 try:
34 with open(args.input) as f:
35 pass
36 except IOError as e:
37 print('input file your enter doesnt exist!')
38
39 # added to check is our model right or not
40 try:
41 for i in args.model:
42 with open(i) as f:
43 pass
44 except IOError as e:
45 print('model you enter doesnt exist, write correct PATH ')
46
47 return args
48
49
50def save_result(output_path, output_data):
51 """
52 This function save result of nn working in .hdf5 file
53 :param output_path: you specify directory to store your result
54 :param output_data: information that you write to .hdf5 file
55 :return:
56 """
57 with open(output_path + 'responce.txt', 'w+') as f:
58 f.write(str(output_data))
59 f = h5py.File(output_path + 'responce.hdf5', 'w')
60 f.create_dataset('out', dtype='float32', data=output_data)
61 f.close()
62
63
64def read_input(input_path):
65 h5f = h5py.File(input_path, 'r')
66 for t in h5f:
67 tensorName = str(t)
68 return h5py.File(input_path, 'r')[tensorName][:]
read_input(input_path)
save_result(output_path, output_data)