示例#1
0
 def test_caffe_priorbox_density_infer(self):
     graph = build_graph(
         nodes_attributes, [('node_1', 'pb'), ('pb', 'node_3')], {
             'node_3': {
                 'is_output': True,
                 'shape': None
             },
             'node_1': {
                 'shape': np.array([1, 128, 32, 32])
             },
             'pb': {
                 'aspect_ratio': np.array([1]),
                 'flip': 1,
                 'min_size': np.array([]),
                 'max_size': np.array([]),
                 'fixed_size': np.array([32, 64, 128]),
                 'density': np.array([1, 2, 4]),
             }
         })
     graph.graph['layout'] = 'NCHW'
     pb_node = Node(graph, 'pb')
     PriorBoxOp.priorbox_infer(pb_node)
     exp_shape = np.array([1, 2, 4 * 32 * 32 * 21])
     res_shape = graph.node['node_3']['shape']
     for i in range(0, len(exp_shape)):
         self.assertEqual(exp_shape[i], res_shape[i])
示例#2
0
    def extract(cls, node):
        variance = onnx_attr(node,
                             'variance',
                             'floats',
                             default=[],
                             dst_type=lambda x: np.array(x, dtype=np.float32))
        if len(variance) == 0:
            variance = [0.1]

        update_attrs = {
            'aspect_ratio':
            onnx_attr(node,
                      'aspect_ratio',
                      'floats',
                      dst_type=lambda x: np.array(x, dtype=np.float32)),
            'min_size':
            onnx_attr(node,
                      'min_size',
                      'floats',
                      dst_type=lambda x: np.array(x, dtype=np.float32)),
            'max_size':
            onnx_attr(node,
                      'max_size',
                      'floats',
                      dst_type=lambda x: np.array(x, dtype=np.float32)),
            'flip':
            onnx_attr(node, 'flip', 'i', default=0),
            'clip':
            onnx_attr(node, 'clip', 'i', default=0),
            'variance':
            list(variance),
            'img_size':
            onnx_attr(node, 'img_size', 'i', default=0),
            'img_h':
            onnx_attr(node, 'img_h', 'i', default=0),
            'img_w':
            onnx_attr(node, 'img_w', 'i', default=0),
            'step':
            onnx_attr(node, 'step', 'f', default=0.0),
            'step_h':
            onnx_attr(node, 'step_h', 'f', default=0.0),
            'step_w':
            onnx_attr(node, 'step_w', 'f', default=0.0),
            'offset':
            onnx_attr(node, 'offset', 'f', default=0.0),
        }

        # update the attributes of the node
        PriorBoxOp.update_node_stat(node, update_attrs)
        return cls.enabled
示例#3
0
    def extract(cls, node):
        proto_layer = node.pb
        param = proto_layer.prior_box_param

        variance = param.variance
        if len(variance) == 0:
            variance = [0.1]

        update_attrs = {
            'aspect_ratio': np.array(param.aspect_ratio),
            'min_size': np.array(param.min_size),
            'max_size': np.array(param.max_size),
            'flip': int(param.flip),
            'clip': int(param.clip),
            'variance': list(variance),
            'img_size': param.img_size,
            'img_h': param.img_h,
            'img_w': param.img_w,
            'step': param.step,
            'step_h': param.step_h,
            'step_w': param.step_w,
            'offset': param.offset,
        }

        # these params can be omitted in caffe.proto and in param as consequence,
        # so check if it is set or set to default
        fields = [field[0].name for field in param.ListFields()]
        if 'density' in fields:
            update_attrs['density'] = np.array(param.density)
        if 'fixed_size' in fields:
            update_attrs['fixed_size'] = np.array(param.fixed_size)
        if 'fixed_ratio' in fields:
            update_attrs['fixed_ratio'] = np.array(param.fixed_ratio)

        mapping_rule = merge_attrs(param, update_attrs)

        mapping_rule.update(layout_attrs())

        # update the attributes of the node
        PriorBoxOp.update_node_stat(node, mapping_rule)
        return cls.enabled
示例#4
0
 def test_tf_priorbox_infer(self):
     graph = build_graph(
         nodes_attributes, [('node_1', 'pb'), ('pb', 'node_3'),
                            ('node_3', 'op_output')], {
                                'node_3': {
                                    'shape': None
                                },
                                'node_1': {
                                    'shape': np.array([1, 19, 19, 384])
                                },
                                'pb': {
                                    'aspect_ratio': np.array([1]),
                                    'flip': 0,
                                    'min_size': np.array([1]),
                                    'max_size': np.array([1])
                                }
                            })
     graph.graph['layout'] = 'NHWC'
     pb_node = Node(graph, 'pb')
     PriorBoxOp.priorbox_infer(pb_node)
     exp_shape = np.array([1, 2, 4 * 19 * 19 * 2])
     res_shape = graph.node['node_3']['shape']
     for i in range(0, len(exp_shape)):
         self.assertEqual(exp_shape[i], res_shape[i])