24helpstr =
'Usage: -f (tfl | caf) ' + \
25 '-t <testcases_directory> ' + \
26 '[-i <input_layer_name>] ' + \
28 '[-p <number_of_processes> <process number>]'
30supported_frameworks = [
'tfl',
'caf']
38for i
in range(len(sys.argv)):
40 if arg ==
'-r' or arg ==
'-b':
42 elif arg ==
'-f' or arg ==
'-t' or arg ==
'-i':
43 if i + 1 >= argc
or sys.argv[i + 1][0] ==
'-':
44 print(arg,
" is missing it's value")
47 args[arg] = sys.argv[i + 1]
49 if i + 2 >= argc
or sys.argv[i + 1][0] ==
'-' or sys.argv[i + 2][0] ==
'-':
50 print(arg,
" is missing some of it's values")
53 args[arg] = (int(sys.argv[i + 1]), int(sys.argv[i + 2]))
55 print(
'Unsupported argument: ', arg)
58if not (
'-f' in args
and '-t' in args):
59 print(
'Some arguments are not provided')
64if not fw
in supported_frameworks:
65 print(
'Unsupported framework: ', fw)
76 inputname = args[
'-i']
78nproc, proc_num = args[
'-p']
79remove_existing = args[
'-r']
80gen_binary = args[
'-b']
82print(
'started at', datetime.datetime.now())
83testcases = glob.glob(indirname +
'/testcase*/')
85testcases = testcases[proc_num - 1::nproc]
88for testcase
in testcases:
90 infilename = glob.glob(testcase +
'input/*.JPEG')
91 if len(infilename) > 0:
93 infilename = infilename[0]
94 outfilename = testcase +
'input/' + infilename.split(
'/')[-1] +
'.hdf5'
95 binoutfilename = testcase +
'input/' + infilename.split(
'/')[-1] +
'.dat'
96 found_hdf = len(glob.glob(outfilename)) != 0
97 found_bin = len(glob.glob(binoutfilename)) != 0
98 if not found_hdf
or (
not found_bin
and gen_binary)
or remove_existing:
99 with Image.open(infilename)
as im:
118 if not found_hdf
or remove_existing:
120 reds = np.fromstring(rfb, count=(h * w), dtype=
'float32')
121 greens = np.fromstring(gfb, count=(h * w), dtype=
'float32')
122 blues = np.fromstring(bfb, count=(h * w), dtype=
'float32')
124 dset_shape = (1, h, w, 3)
125 narr = np.ndarray(shape=(0))
127 for i
in range(h * w):
129 reds[i] / 255.0, greens[i] / 255.0, blues[i] / 255.0
131 narr = np.append(narr, mixed_ch)
133 dset_shape = (1, 3, h, w)
134 narr = np.fromstring(rfb + gfb + bfb,
137 for i
in range(3 * h * w):
140 subprocess.call([
'rm',
'-f', outfilename])
141 with h5py.File(outfilename)
as f:
143 dset = f.require_dataset(inputname, dset_shape, dtype=
'>f4')
144 dset[0] = np.reshape(narr, dset_shape)
147 if gen_binary
and (
not found_bin
or remove_existing):
148 if fw ==
'tfl' and made_hdf:
151 reds = np.fromstring(rfb, count=(h * w), dtype=
'float32')
152 greens = np.fromstring(gfb, count=(h * w), dtype=
'float32')
153 blues = np.fromstring(bfb, count=(h * w), dtype=
'float32')
154 l = np.ndarray(shape=(0))
156 for i
in range(h * w):
158 reds[i] / 255.0, greens[i] / 255.0, blues[i] / 255.0
160 l = np.append(l, mixed_ch)
162 with open(binoutfilename,
'wb')
as out:
163 out.write(struct.pack(
'f' * len(l), *l))
164 print(number,
': ' + testcase +
' Done')
166 print(testcase,
' nothing to do')
168 print(testcase,
' JPEG not found')
170 print(testcase,
" FAILED")
171print(
'started at', ended.datetime.now())