diff --git a/mace/python/tools/converter_tool/hexagon_converter.py b/mace/python/tools/converter_tool/hexagon_converter.py index d20e7ef262b4e8a57652ce5cc5539f0cda2d7b8b..121ee494563cab238750c4c063d6e44af354cce2 100644 --- a/mace/python/tools/converter_tool/hexagon_converter.py +++ b/mace/python/tools/converter_tool/hexagon_converter.py @@ -116,7 +116,7 @@ class HexagonConverter(base_converter.ConverterInterface): for op in self._model.op: if not self._hexagon_ops.has_op(op.type): raise Exception('Unsupported op: ', op) - print('Op: ', op.name, op.type) + print('Op: %s (%s)' % (op.name, op.type)) for i in range(len(op.input)): if ':' not in op.input[i]: node_name = op.input[i] diff --git a/mace/python/tools/converter_tool/transformer.py b/mace/python/tools/converter_tool/transformer.py index 86982a2ce97b367e72e0985e7c73671d31f897a0..0c585b615365a694aebc05860fb8259ce5ec4625 100644 --- a/mace/python/tools/converter_tool/transformer.py +++ b/mace/python/tools/converter_tool/transformer.py @@ -1482,7 +1482,9 @@ class Transformer(base_converter.ConverterInterface): mace_check(False, "wrong device.") tensor.data_type = mace_pb2.DT_INT32 else: - quantized_tensor = quantize_util.quantize(tensor.float_data) + non_zero = self._option.device == DeviceType.CPU.value + quantized_tensor = quantize_util.quantize(tensor.float_data, + non_zero) tensor.data_type = mace_pb2.DT_UINT8 del tensor.float_data[:] @@ -1718,6 +1720,11 @@ class Transformer(base_converter.ConverterInterface): and op.type != MaceOp.Dequantize.name): # noqa mace_check(len(op.output) == len(op.quantize_info), "missing quantize info: %s" % op) + for i in six.moves.range(len(op.quantize_info)): + print("Op output %s range: [%f, %f]" % ( + op.output[i], + op.quantize_info[i].minval, + op.quantize_info[i].maxval)) def add_opencl_informations(self): print("Add OpenCL informations") diff --git a/mace/python/tools/quantization/quantize_util.py b/mace/python/tools/quantization/quantize_util.py index 346073bde43fae73b07277ee0bc83c89d99c1381..349393870e24e39073761bd10faffc4277a7335d 100644 --- a/mace/python/tools/quantization/quantize_util.py +++ b/mace/python/tools/quantization/quantize_util.py @@ -108,11 +108,12 @@ def quantize_with_scale_and_zero(data, scale, zero): return quantized_data -def quantize(data): +def quantize(data, non_zero): np_data = np.array(data).astype(float) in_min = np_data.min() in_max = np_data.max() - scale, zero, out_min, out_max = adjust_range(in_min, in_max, non_zero=True) + scale, zero, out_min, out_max = adjust_range(in_min, in_max, + non_zero=non_zero) output = np.clip((np.round(zero + data / scale).astype(int)), 0, 255) quantized_data = QuantizedData()