コード例 #1
0
    def extract(node):
        param = node.pb.python_param
        attrs = CaffePythonFrontExtractorOp.parse_param_str(param.param_str)
        update_attrs = {
            'feat_stride': 16,
            'base_size': 16,
            'min_size': 16,
            'ratio': [0.5, 1, 2],
            'scale': [8, 16, 32],
            'pre_nms_topn': 6000,
            'post_nms_topn': 300,
            'nms_thresh': 0.7
        }
        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(
            Op.get_op_class_by_name('Proposal'), update_attrs)
        Op.get_op_class_by_name('Proposal').update_node_stat(
            node, update_attrs)
        return __class__.enabled
コード例 #2
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(
            Op.get_op_class_by_name('Proposal'), update_attrs)
        Op.get_op_class_by_name('Proposal').update_node_stat(
            node, update_attrs)
コード例 #3
0
 def test_python_extractor_for_op(self):
     module = 'test_module'
     layer = 'test_layer'
     CaffePythonFrontExtractorOp.registered_ops['{}.{}'.format(module, layer)] = \
         lambda node: CaffePythonFrontExtractorOp.parse_param_str(node.pb.python_param.param_str)
     params = FakeMultiParam({
         'module': module,
         'layer': layer,
         'param_str': "'feat_stride': 16"
     })
     ext = PythonFrontExtractorOp.extract(FakeNode(FakePythonProtoLayer(params), None))
     self.assertEqual({'feat_stride': 16}, ext)
コード例 #4
0
 def test_get_attrs(self):
     exp_attrs = {"test_attr_1": 12, "test_attr_2": "sdf sdf"}
     param_str = "'test_attr_1': 12, 'test_attr_2': 'sdf sdf'"
     attrs = CaffePythonFrontExtractorOp.get_attrs(
         FakePythonParam(FakeMultiParam({'param_str': param_str})))
     self.assertEqual(exp_attrs, attrs)