Пример #1
0
    def test_proposal_infer_one_output(self):
        graph = build_graph(nodes_attributes,
                            [('proposal_input', 'proposal'),
                             ('proposal', 'proposal_out_data_1'),
                             ('proposal_out_data_1', 'op_output')
                             ],
                            {'proposal_input': {'shape': int64_array([1, 3, 227, 227])},
                             'proposal': {'post_nms_topn': 2, **layout_attrs()}
                             })

        proposal_node = Node(graph, 'proposal')
        ProposalOp.proposal_infer(proposal_node)

        self.assertListEqual([1 * 2, 5], list(graph.node['proposal_out_data_1']['shape']))
Пример #2
0
    def test_proposal_infer(self):
        graph = build_graph(nodes_attributes,
                            [('node_1', 'proposal'),
                             ('proposal', 'node_3')],
                            {'node_3': {'is_output': True, 'shape': None},
                             'node_1': {'shape': np.array([1, 3, 227, 227])},
                             'proposal': {'post_nms_topn': 2, **layout_attrs()}
                             })

        proposal_node = Node(graph, 'proposal')
        ProposalOp.proposal_infer(proposal_node)
        exp_shape = np.array([1 * 2, 5])
        res_shape = graph.node['node_3']['shape']
        for i in range(0, len(exp_shape)):
            self.assertEqual(exp_shape[i], res_shape[i])
Пример #3
0
    def extract(cls, node):
        proto_layer = node.pb
        param = proto_layer.proposal_param
        update_attrs = {
            'feat_stride': param.feat_stride,
            'base_size': param.base_size,
            'min_size': param.min_size,
            'ratio': np.array(param.ratio),
            'scale': np.array(param.scale),
            'pre_nms_topn': param.pre_nms_topn,
            'post_nms_topn': param.post_nms_topn,
            'nms_thresh': param.nms_thresh
        }

        mapping_rule = merge_attrs(param, update_attrs)
        # update the attributes of the node
        ProposalOp.update_node_stat(node, mapping_rule)
        return cls.enabled
Пример #4
0
    def extract(self, node):
        attrs = get_mxnet_layer_attrs(node.symbol_dict)
        feat_stride = attrs.int("feat_stride", 16)
        ratio = attrs.tuple("ratios", float, (0.5, 1, 2))
        scale = attrs.tuple("scales", int, (4, 8, 16, 32))
        min_size = attrs.int("rpn_min_size", 16)
        pre_nms_topn = attrs.int("rpn_pre_nms_top_n", 6000)
        post_nms_topn = attrs.int("rpn_post_nms_top_n", 300)
        nms_thresh = attrs.float("threshold", 0.7)

        node_attrs = {
            'feat_stride': feat_stride,
            'base_size': 0,
            'min_size': min_size,
            'ratio': np.array(ratio),
            'scale': np.array(scale),
            'pre_nms_topn': pre_nms_topn,
            'post_nms_topn': post_nms_topn,
            'nms_thresh': nms_thresh,
        }

        ProposalOp.update_node_stat(node, node_attrs)
        return (True, node_attrs)
Пример #5
0
    def extract_proposal_params(node, defaults):
        param = node.pb.python_param
        attrs = CaffePythonFrontExtractorOp.parse_param_str(param.param_str)
        update_attrs = defaults
        if 'ratios' in attrs and 'ratio' in attrs:
            log.error(
                'Both ratios and ratio found, value of ratios will be used',
                extra={'is_warning': True})
        if 'scales' in attrs and 'scale' in attrs:
            log.error(
                'Both scales and scale found, value of scales will be used',
                extra={'is_warning': True})

        if 'ratios' in attrs:
            attrs['ratio'] = attrs['ratios']
            del attrs['ratios']
        if 'scales' in attrs:
            attrs['scale'] = attrs['scales']
            del attrs['scales']

        update_attrs.update(attrs)
        CaffePythonFrontExtractorOp.check_param(ProposalOp, update_attrs)
        ProposalOp.update_node_stat(node, update_attrs)
Пример #6
0
    def extract(cls, node):
        attrs = get_mxnet_layer_attrs(node.symbol_dict)
        pre_nms_topn = attrs.int('rpn_pre_nms_top_n', 6000)
        post_nms_topn = attrs.int('rpn_post_nms_top_n', 300)
        nms_thresh = attrs.float('threshold', 0.7)
        min_size = attrs.int('rpn_min_size', 16)
        scale = attrs.tuple("scales", float, (4, 8, 16, 32))
        ratio = attrs.tuple("ratios", float, (0.5, 1, 2))
        feat_stride = attrs.int('feature_stride', 16)

        update_attrs = {
            'feat_stride': feat_stride,
            'ratio': np.array(ratio),
            'min_size': min_size,
            'scale': np.array(scale),
            'pre_nms_topn': pre_nms_topn,
            'post_nms_topn': post_nms_topn,
            'nms_thresh': nms_thresh,
            'base_size': feat_stride
        }

        # update the attributes of the node
        ProposalOp.update_node_stat(node, update_attrs)
        return cls.enabled