@@ -1512,6 +1512,86 @@ def test_const_dequantize_reshape(self):
1512
1512
model_proto = self .make_model (graph , producer_name = "onnx-tests" )
1513
1513
self .run_and_compare (["Z" ], {}, model_proto , "Reshape" , 0 )
1514
1514
1515
+ @check_opset_min_version (13 , "DequantizeLinear" )
1516
+ def test_const_dequantize_reshape_per_channel (self ):
1517
+ inputval = numpy_helper .from_array (np .random .randint (0 , 100 , (2 , 3 , 4 , 5 ), np .uint8 ), name = 'X' )
1518
+ scale = numpy_helper .from_array (np .array ([0.75 , 1. , 0.2 ], dtype = np .float32 ), name = 'scale' )
1519
+ zero_point = numpy_helper .from_array (np .array ([3 , 4 , 50 ], dtype = np .uint8 ), name = 'zero_point' )
1520
+ shape = numpy_helper .from_array (np .array ([1 , 1 , 2 , 3 , 20 ], dtype = np .int64 ), name = 'shape' )
1521
+ node1 = helper .make_node ("DequantizeLinear" , ["X" , "scale" , "zero_point" ], ["Y" ], name = "dequantize" , axis = - 3 )
1522
+ node2 = helper .make_node ("Reshape" , ["Y" , "shape" ], ["Z" ], name = "reshape" )
1523
+
1524
+ graph = helper .make_graph (
1525
+ [node1 , node2 ],
1526
+ "const-dequantize-test" ,
1527
+ [],
1528
+ [helper .make_tensor_value_info ("Z" , TensorProto .FLOAT , (1 , 1 , 2 , 3 , 20 ))],
1529
+ [inputval , scale , zero_point , shape ]
1530
+ )
1531
+
1532
+ model_proto = self .make_model (graph , producer_name = "onnx-tests" )
1533
+ self .run_and_compare (["Z" ], {}, model_proto , "Reshape" , 0 )
1534
+
1535
+ @check_opset_min_version (13 , "DequantizeLinear" )
1536
+ def test_const_dequantize_reshape_per_channel_skipped (self ):
1537
+ inputval = numpy_helper .from_array (np .random .randint (0 , 100 , (2 , 3 , 4 , 5 ), np .uint8 ), name = 'X' )
1538
+ scale = numpy_helper .from_array (np .array ([0.75 , 1. , 0.2 , 0.3 ], dtype = np .float32 ), name = 'scale' )
1539
+ zero_point = numpy_helper .from_array (np .array ([3 , 4 , 50 , 2 ], dtype = np .uint8 ), name = 'zero_point' )
1540
+ shape = numpy_helper .from_array (np .array ([1 , 6 , 2 , 2 , 5 ], dtype = np .int64 ), name = 'shape' )
1541
+ node1 = helper .make_node ("DequantizeLinear" , ["X" , "scale" , "zero_point" ], ["Y" ], name = "dequantize" , axis = 2 )
1542
+ node2 = helper .make_node ("Reshape" , ["Y" , "shape" ], ["Z" ], name = "reshape" )
1543
+
1544
+ graph = helper .make_graph (
1545
+ [node1 , node2 ],
1546
+ "const-dequantize-test" ,
1547
+ [],
1548
+ [helper .make_tensor_value_info ("Z" , TensorProto .FLOAT , (1 , 6 , 2 , 2 , 5 ))],
1549
+ [inputval , scale , zero_point , shape ]
1550
+ )
1551
+
1552
+ model_proto = self .make_model (graph , producer_name = "onnx-tests" )
1553
+ # No optimization can be done here since the channel axis has changed size
1554
+ self .run_and_compare (["Z" ], {}, model_proto , "Reshape" , 1 )
1555
+
1556
+ @check_opset_min_version (13 , "DequantizeLinear" )
1557
+ def test_const_dequantize_transpose_per_channel (self ):
1558
+ inputval = numpy_helper .from_array (np .random .randint (0 , 100 , (2 , 3 , 4 , 5 ), np .uint8 ), name = 'X' )
1559
+ scale = numpy_helper .from_array (np .array ([0.75 , 1. , 0.2 ], dtype = np .float32 ), name = 'scale' )
1560
+ zero_point = numpy_helper .from_array (np .array ([3 , 4 , 50 ], dtype = np .uint8 ), name = 'zero_point' )
1561
+ node1 = helper .make_node ("DequantizeLinear" , ["X" , "scale" , "zero_point" ], ["Y" ], name = "dequantize" , axis = 1 )
1562
+ node2 = helper .make_node ("Transpose" , ["Y" ], ["Z" ], name = "transpose" , perm = [0 , 2 , 3 , 1 ])
1563
+
1564
+ graph = helper .make_graph (
1565
+ [node1 , node2 ],
1566
+ "const-dequantize-test" ,
1567
+ [],
1568
+ [helper .make_tensor_value_info ("Z" , TensorProto .FLOAT , (2 , 4 , 5 , 3 ))],
1569
+ [inputval , scale , zero_point ]
1570
+ )
1571
+
1572
+ model_proto = self .make_model (graph , producer_name = "onnx-tests" )
1573
+ self .run_and_compare (["Z" ], {}, model_proto , "Transpose" , 0 )
1574
+
1575
+ @check_opset_min_version (13 , "DequantizeLinear" )
1576
+ def test_const_dequantize_unsqueeze_per_channel (self ):
1577
+ inputval = numpy_helper .from_array (np .random .randint (0 , 100 , (2 , 3 , 4 , 5 ), np .uint8 ), name = 'X' )
1578
+ scale = numpy_helper .from_array (np .array ([0.75 , 1. , 0.2 ], dtype = np .float32 ), name = 'scale' )
1579
+ zero_point = numpy_helper .from_array (np .array ([3 , 4 , 50 ], dtype = np .uint8 ), name = 'zero_point' )
1580
+ axes = numpy_helper .from_array (np .array ([- 1 , 0 , - 8 , 3 , 5 ], dtype = np .int64 ), name = 'axes' )
1581
+ node1 = helper .make_node ("DequantizeLinear" , ["X" , "scale" , "zero_point" ], ["Y" ], name = "dequantize" , axis = 1 )
1582
+ node2 = helper .make_node ("Unsqueeze" , ["Y" , "axes" ], ["Z" ], name = "unsqueeze" )
1583
+
1584
+ graph = helper .make_graph (
1585
+ [node1 , node2 ],
1586
+ "const-dequantize-test" ,
1587
+ [],
1588
+ [helper .make_tensor_value_info ("Z" , TensorProto .FLOAT , (1 , 1 , 2 , 1 , 3 , 1 , 4 , 5 , 1 ))],
1589
+ [inputval , scale , zero_point , axes ]
1590
+ )
1591
+
1592
+ model_proto = self .make_model (graph , producer_name = "onnx-tests" )
1593
+ self .run_and_compare (["Z" ], {}, model_proto , "Transpose" , 0 )
1594
+
1515
1595
# Const Dequantize Optimizer Tests End
1516
1596
1517
1597
def test_transpose_back_to_back_non_const (self ):
0 commit comments