@@ -195,8 +195,8 @@ def __del__(self):
195195 avg_q = 0.0
196196 t_str += " {:5.1f}" .format (avg_time )
197197 q_str += " {:5.1f}" .format (avg_q )
198- c_str += " {:5d }" .format (c )
199- logging .info (f"{ self .tpu_name } timing , queue len, & count:{ t_str } ;{ q_str } ;{ c_str } " )
198+ c_str += " {:7d }" .format (c )
199+ logging .info (f"{ self .tpu_name } time , queue len, & count:{ t_str } ;{ q_str } ;{ c_str } " )
200200
201201 self .interpreter = None
202202 self .input_details = None
@@ -496,9 +496,9 @@ def _get_tpu_devices(self):
496496 ['usb:%d' % i for i in range (max (0 , len (edge_tpus ) - num_pci_devices ))]
497497
498498 if self .tpu_limit > 0 :
499- return tpu_l [4 :self .tpu_limit ]
499+ return tpu_l [:self .tpu_limit ]
500500 else :
501- return tpu_l [ 4 :]
501+ return tpu_l
502502
503503
504504 def _get_model_filenames (self , options : Options , tpu_list : list ) -> list :
@@ -1173,6 +1173,9 @@ def to_numpy(im, shape, typestr):
11731173 "Mapping {} image to {}x{} tiles" .format (image .size , tiles_x , tiles_y ))
11741174 self .printed_shape_map [key ] = True
11751175
1176+ input_zero = self .input_details ['quantization' ][1 ]
1177+ input_scale = 1.0 / (256.0 * self .input_details ['quantization' ][0 ])
1178+
11761179 # Do chunking
11771180 tiles = []
11781181 for x_off in range (0 , resamp_x - options .tile_overlap , m_width - options .tile_overlap ):
@@ -1187,11 +1190,11 @@ def to_numpy(im, shape, typestr):
11871190
11881191 # Normalize from 8-bit image to whatever the input is
11891192 if self .input_details ['dtype' ] == np .int8 :
1190- tiles .append (((cropped_arr - 128 ).astype (np .int8 ), resamp_info ))
1193+ cropped_arr = cropped_arr * input_scale + input_zero
1194+ tiles .append ((cropped_arr .astype (np .int8 ), resamp_info ))
11911195 else :
11921196 tiles .append ((cropped_arr , resamp_info ))
11931197
1194- #Image.fromarray((tiles[-1][0] + 128).astype(np.uint8)).save("test.png")
11951198 return tiles
11961199
11971200
0 commit comments