def test6(self): # Original graph # data(1,64,1)-->Reduce(axis=-2,keep_dims=True, reduce_type=Sum)-->data(1,1,1) # # Reference graph # data(1,61,1)->Reshape(1,1,8,8)->Pool(1,1,1,1)->Reshape(1,1,1)->Power(scale=64) # graph = build_graph(nodes_attributes, [('placeholder_1', 'placeholder_1_data'), ('placeholder_1_data', 'reduce_1'), ('const', 'const_data'), ('const_data', 'reduce_1', {'in': 1}), ('reduce_1', 'reduce_1_data'), ('reduce_1_data', 'concat'), ], {'placeholder_1': {'shape': int64_array([1, 64, 1])}, 'placeholder_1_data': {'shape': int64_array([1, 64, 1])}, 'reduce_1': {'keep_dims': True, 'type': 'ReduceSum'}, 'const_data': {'value': int64_array([-2])}, 'reduce_1_data': {'shape': int64_array([1, 1, 1])}, }, nodes_with_edges_only=True) graph.graph['layout'] = 'NCHW' graph_ref = build_graph(nodes_attributes, [('placeholder_1', 'placeholder_1_data'), ('placeholder_1_data', 'reshape_1'), ('reshape_1_const', 'reshape_1_const_data'), ('reshape_1_const_data', 'reshape_1'), ('reshape_1', 'reshape_1_data'), ('reshape_1_data', 'pooling'), ('pooling', 'pooling_data'), ('pooling_data', 'reshape_2'), ('reshape_2_const', 'reshape_2_const_data'), ('reshape_2_const_data', 'reshape_2'), ('reshape_2', 'reshape_2_data'), ('reshape_2_data', 'power'), ('power', 'power_data'), ('power_data', 'concat'), ], {'placeholder_1': {'shape': int64_array([1, 64, 1])}, 'placeholder_1_data': {'shape': int64_array([1, 64, 1])}, 'reshape_1_const': {'value': int64_array([0, 1, 8, 8]), 'shape': int64_array([4])}, 'reshape_1_const_data': {'value': int64_array([0, 1, 8, 8]), 'shape': int64_array([4])}, 'reshape_1_data': {'shape': int64_array([1, 1, 8, 8])}, 'pooling': {'window': int64_array([1, 1, 8, 8])}, 'pooling_data': {'shape': int64_array([1, 1, 1, 1])}, 'reshape_2_const': {'value': int64_array([0, 1, 1]), 'shape': int64_array([3])}, 'reshape_2_const_data': {'value': int64_array([0, 1, 1]), 'shape': int64_array([3])}, 'reshape_2_data': {'shape': int64_array([1, 1, 1])}, 'power': {'scale': 64.0}, 'power_data': {'shape': int64_array([1, 1, 1])}, }, nodes_with_edges_only=True) ReduceReplacer().find_and_replace_pattern(graph) shape_inference(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat', check_op_attrs=True) self.assertTrue(flag, resp)
def test5(self): # Original graph # data(1, 16, 64, 64, 64, 4)-->Reduce(axis=[5],keep_dims=False)-->data(1, 16, 64, 64, 64) # # Reference graph # data(1, 16, 64, 64, 64, 4)->Reshape(1*16*64*64, 64, 2, 2)->Pool(1, 1, 2, 2)->Reshape(1, 16, 64, 64, 64) # graph = build_graph(nodes_attributes, [('placeholder_1', 'placeholder_1_data'), ('placeholder_1_data', 'reduce_1'), ('const', 'const_data'), ('const_data', 'reduce_1', {'in': 1}), ('reduce_1', 'reduce_1_data'), ('reduce_1_data', 'concat'), ], {'placeholder_1': {'shape': int64_array([1, 16, 64, 64, 64, 4])}, 'placeholder_1_data': {'shape': int64_array([1, 16, 64, 64, 64, 4])}, 'reduce_1': {'keep_dims': False, 'type': 'ReduceMax'}, 'const_data': {'value': int64_array([5])}, 'reduce_1_data': {'shape': int64_array([1, 16, 64, 64, 64])}, }, nodes_with_edges_only=True) graph.graph['layout'] = 'NCHW' graph_ref = build_graph(nodes_attributes, [('placeholder_1', 'placeholder_1_data'), ('placeholder_1_data', 'reshape_1'), ('reshape_1_const', 'reshape_1_const_data'), ('reshape_1_const_data', 'reshape_1'), ('reshape_1', 'reshape_1_data'), ('reshape_1_data', 'pooling'), ('pooling', 'pooling_data'), ('pooling_data', 'reshape_2'), ('reshape_2_const', 'reshape_2_const_data'), ('reshape_2_const_data', 'reshape_2'), ('reshape_2', 'reshape_2_data'), ('reshape_2_data', 'concat'), ], {'placeholder_1': {'shape': int64_array([1, 16, 64, 64, 64, 4])}, 'placeholder_1_data': {'shape': int64_array([1, 16, 64, 64, 64, 4])}, 'reshape_1_const': {'value': int64_array([0, 4194304, 2, 2]), 'shape': int64_array([4])}, 'reshape_1_const_data': {'value': int64_array([0, 4194304, 2, 2]), 'shape': int64_array([4])}, 'reshape_1_data': {'shape': int64_array([1, 4194304, 2, 2])}, 'pooling': {'window': int64_array([1, 1, 2, 2])}, 'pooling_data': {'shape': int64_array([1, 4194304, 1, 1])}, 'reshape_2_const': {'value': int64_array([0, 16, 64, 64, 64]), 'shape': int64_array([5])}, 'reshape_2_const_data': {'value': int64_array([0, 16, 64, 64, 64]), 'shape': int64_array([5])}, 'reshape_2_data': {'shape': int64_array([1, 16, 64, 64, 64])}, }, nodes_with_edges_only=True) ReduceReplacer().find_and_replace_pattern(graph) shape_inference(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat', check_op_attrs=True) self.assertTrue(flag, resp)