def test_topo_sort_constant(self): test_model_path = "onnx_model_topo_sort_constant.onnx" self.construct_model_Constant(test_model_path) onnx_model = ONNXModel(onnx.load(test_model_path)) check_op_type_order(self, onnx_model.model, ["Add", "Constant"]) onnx_model.topological_sort() check_op_type_order(self, onnx_model.model, ["Constant", "Add"])
def verify(self, per_channel): np.random.seed(1) model_fp32_path = 'conv_clip_fp32.{}.onnx'.format(per_channel) model_int8_qdq_path = 'conv_clip_quant_qdq.{}.onnx'.format(per_channel) model_int8_qop_path = 'conv_clip_quant_qop.{}.onnx'.format(per_channel) data_reader = self.input_feeds(1, {'input': [1, 8, 33, 33]}) self.construct_model_conv_clip(model_fp32_path, [1, 8, 33, 33], [16, 8, 3, 3], [15376]) quantize_static(model_fp32_path, model_int8_qdq_path, data_reader, quant_format=QuantFormat.QDQ, per_channel = per_channel, reduce_range = per_channel ) data_reader.rewind() #topo sort check check_op_type_order(self, model_int8_qdq_path, ['DequantizeLinear', 'QuantizeLinear', 'DequantizeLinear', 'Conv', 'QuantizeLinear', 'DequantizeLinear', 'Reshape', 'QuantizeLinear', 'DequantizeLinear']) check_model_correctness(self, model_fp32_path, model_int8_qdq_path, data_reader.get_next()) data_reader.rewind() quantize_static(model_fp32_path, model_int8_qop_path, data_reader, quant_format=QuantFormat.QOperator, per_channel = per_channel, reduce_range = per_channel ) data_reader.rewind() qop_nodes = {'QLinearConv': 1, 'QuantizeLinear': 1, 'DequantizeLinear': 1} check_op_type_count(self, model_int8_qop_path, **qop_nodes) check_model_correctness(self, model_fp32_path, model_int8_qop_path, data_reader.get_next())
def test_topo_sort_constant(self): test_model_path = 'onnx_model_topo_sort_constant.onnx' self.construct_model_Constant(test_model_path) onnx_model = ONNXModel(onnx.load(test_model_path)) check_op_type_order(self, onnx_model.model, ['Add', 'Constant']) onnx_model.topological_sort() check_op_type_order(self, onnx_model.model, ['Constant', 'Add'])
def verify(self, per_channel, is_quant_type_int8): np.random.seed(1) model_fp32_path = "conv_relu_fp32.{}.onnx".format(per_channel) model_int8_qdq_path = "conv_relu_quant_qdq.{}.onnx".format(per_channel) model_int8_qop_path = "conv_relu_quant_qop.{}.onnx".format(per_channel) data_reader = self.input_feeds(1, {"input": [1, 8, 33, 33]}) self.construct_model_conv_relu(model_fp32_path, [1, 8, 33, 33], [16, 8, 3, 3], [1, 16, 31, 31]) quantize_static( model_fp32_path, model_int8_qdq_path, data_reader, quant_format=QuantFormat.QDQ, per_channel=per_channel, reduce_range=per_channel, activation_type=QuantType.QInt8 if is_quant_type_int8 else QuantType.QUInt8, weight_type=QuantType.QInt8 if is_quant_type_int8 else QuantType.QUInt8, ) data_reader.rewind() # topo sort check check_op_type_order( self, model_int8_qdq_path, [ "DequantizeLinear", "QuantizeLinear", "DequantizeLinear", "Conv", "QuantizeLinear", "DequantizeLinear", ], ) check_model_correctness(self, model_fp32_path, model_int8_qdq_path, data_reader.get_next()) data_reader.rewind() quantize_static( model_fp32_path, model_int8_qop_path, data_reader, quant_format=QuantFormat.QOperator, per_channel=per_channel, reduce_range=per_channel, activation_type=QuantType.QInt8 if is_quant_type_int8 else QuantType.QUInt8, weight_type=QuantType.QInt8 if is_quant_type_int8 else QuantType.QUInt8, ) data_reader.rewind() qop_nodes = { "QLinearConv": 1, "QuantizeLinear": 1, "DequantizeLinear": 1 } check_op_type_count(self, model_int8_qop_path, **qop_nodes) check_model_correctness(self, model_fp32_path, model_int8_qop_path, data_reader.get_next())