示例#1
0
    def test_image_scaler_test_8(self):
        graph = build_graph(nodes_attributes, [
            ('placeholder_1', 'im_scaler'),
            ('im_scaler', 'last'),
        ], {
            'placeholder_1': {
                'shape': np.array([1, 227, 227, 3])
            },
            'im_scaler': {
                'scale': np.array(1.0),
                'bias': np.reshape(np.array([0, 0, 0]), [3, 1, 1])
            },
        },
                            nodes_with_edges_only=True)

        graph_ref = build_graph(nodes_attributes, [('placeholder_1', 'last')],
                                {
                                    'placeholder_1': {
                                        'shape': np.array([1, 227, 227, 3])
                                    },
                                },
                                nodes_with_edges_only=True)

        graph.graph['layout'] = 'NCHW'
        graph.stage = 'front'

        replacer = ImageScaler()
        replacer.find_and_replace_pattern(graph)

        (flag, resp) = compare_graphs(graph, graph_ref, 'last')
        self.assertTrue(flag, resp)
示例#2
0
    def test_image_scaler_test_1(self):
        graph = build_graph(nodes_attributes, [
            ('placeholder_1', 'placeholder_1_data'),
            ('placeholder_1_data', 'im_scaler'),
            ('im_scaler', 'im_scaler_data'),
            ('im_scaler_data', 'last'),
        ], {
            'placeholder_1_data': {
                'shape': np.array([1, 227, 227, 3])
            },
            'im_scaler': {
                'scale': np.array(2.0),
                'bias': np.reshape(np.array([1, 2, 3]), [3, 1, 1])
            },
        },
                            nodes_with_edges_only=True)

        graph_ref = build_graph(
            nodes_attributes, [('placeholder_1', 'placeholder_1_data'),
                               ('placeholder_1_data', 'mul_1'),
                               ('const_mul_1_w', 'mul_1_w'),
                               ('mul_1_w', 'mul_1'), ('mul_1', 'mul_1_data'),
                               ('mul_1_data', 'add_1'),
                               ('const_add_1_w', 'add_1_w'),
                               ('add_1_w', 'add_1'), ('add_1', 'add_1_data'),
                               ('add_1_data', 'last')],
            {
                'placeholder_1_data': {
                    'shape': np.array([1, 227, 227, 3])
                },
                'const_mul_1_w': {
                    'shape': np.array(2.0).shape,
                    'value': np.array(2.0)
                },
                'const_add_1_w': {
                    'shape': np.array([3, 1, 1]),
                    'value': np.reshape(np.array([1, 2, 3]), [3, 1, 1])
                },
            },
            nodes_with_edges_only=True)

        graph.graph['layout'] = 'NCHW'
        graph.stage = 'middle'

        replacer = ImageScaler()
        replacer.find_and_replace_pattern(graph)

        (flag, resp) = compare_graphs(graph, graph_ref, 'last')
        self.assertTrue(flag, resp)