Пример #1
0
    def test_attrs(self):
        params = {
            'type_str': 'Deconv2D',
            'padding': [10, 10],
            'stride': [12, 12],
            'kernel': [11, 11],
            'dilate': [13, 13],
            'group': 14,
            'output': 13,
            'bias_term': True
        }
        res = conv_create_attrs(params)

        exp_res = {
            'pad': np.array([[0, 0], [0, 0], [10, 10], [10, 10]]),
            'pad_spatial_shape': np.array([[10, 10], [10, 10]]),
            'stride': np.array([1, 1, 12, 12]),
            'kernel_spatial': np.array([11, 11]),
            'dilation': np.array([1, 1, 13, 13]),
            'group': 14,
            'bias_addable': True,
            'output_spatial_shape': None,
            'output_shape': None,
            'output': 13,
        }
        for key in exp_res.keys():
            if key in ('pad', 'pad_spatial_shape', 'stride', 'kernel_spatial',
                       'dilation'):
                np.testing.assert_equal(res[key], exp_res[key])
            else:
                self.assertEqual(res[key], exp_res[key])
Пример #2
0
    def extract(node):
        proto_layer, model_layer = node.pb, node.model_pb

        if not proto_layer:
            raise Error('Protobuf layer can not be empty')

        conv_param = proto_layer.convolution_param
        conv_type = 'ConvND' if len(proto_layer.bottom) > 1 else 'Conv2D'

        params = conv_set_params(conv_param, conv_type)
        attrs = conv_create_attrs(params)
        attrs.update({
            'op': __class__.op,
            'get_group': lambda node: node.group,
            'get_output_feature_dim': lambda node: node.output,
            'weights_index': 1 if conv_type == 'Conv2D' else 2
        })

        # Embed weights and biases as attributes
        # It will be moved to a separate nodes in special pass
        attrs.update(
            weights_biases(conv_param.bias_term,
                           model_layer,
                           start_index=len(proto_layer.bottom),
                           proto=conv_param))
        attrs.update(layout_attrs())

        # update the attributes of the node
        Convolution.update_node_stat(node, attrs)
        return __class__.enabled