Exemplo n.º 1
0
    def extract(cls, node):
        attrs = tf_create_attrs(node, 2, 3)

        def get_num_groups(node):
            if 'group' in node:
                return node.group
            elif node.in_node(0).shape is not None and node.kernel_shape is not None \
                    and node.in_node(0).shape[node.channel_dims[0]] is not dynamic_dimension \
                    and node.kernel_shape[node.input_feature_channel] is not dynamic_dimension:
                # if group attribute is not defined, number of groups is calculated
                # from number of input channels and filter channel size
                return node.in_node(0).shape[
                    node.channel_dims] // node.kernel_shape[
                        node.input_feature_channel]
            else:
                return 1

        attrs.update({
            'op':
            __class__.op,
            'get_group':
            get_num_groups,
            'get_output_feature_dim':
            lambda node: node.kernel_shape[node.output_feature_channel],
            'get_weights_permute':
            PermuteAttrs.Permutation(perm=int64_array([3, 2, 0, 1]),
                                     inv=int64_array([2, 3, 1, 0]))
        })

        # update the attributes of the node
        Convolution.update_node_stat(node, attrs)
        return cls.enabled
Exemplo n.º 2
0
    def extract(cls, node):
        attrs = tf_create_attrs(node, 3, 4)
        attrs.update({
            'op':
            __class__.op,
            'get_group':
            lambda node: 1,
            'get_output_feature_dim':
            lambda node: node.kernel_shape[node.output_feature_channel],
            'get_weights_permute':
            PermuteAttrs.Permutation(perm=int64_array([4, 3, 0, 1, 2]),
                                     inv=int64_array([2, 3, 4, 1, 0]))
        })

        # update the attributes of the node
        Convolution.update_node_stat(node, attrs)
        return cls.enabled
Exemplo n.º 3
0
    def extract(cls, node):
        attrs = tf_create_attrs(node, 4, 3)
        attrs.update({
            'op':
            cls.op,
            'get_weights_permute':
            PermuteAttrs.Permutation(perm=int64_array([4, 3, 0, 1, 2]),
                                     inv=int64_array([2, 3, 4, 1, 0])),
            'swap_0_and_2_inputs':
            True,
            'shape_input':
            True,
        })

        # update the attributes of the node
        Deconvolution.update_node_stat(node, attrs)
        return cls.enabled
Exemplo n.º 4
0
    def extract(cls, node):
        attrs = tf_create_attrs(node, 2, 2)
        attrs.update({
            'op':
            __class__.op,
            'kernel_spatial_idx':
            np.array([0, 1], dtype=np.int64),
            'get_group':
            lambda node: node.kernel_shape[node.output_feature_channel],
            'get_output_feature_dim':
            lambda node: node.kernel_shape[-1] * node.kernel_shape[-2],
            'get_weights_permute':
            PermuteAttrs.Permutation(perm=int64_array([2, 3, 0, 1]),
                                     inv=int64_array([2, 3, 0, 1]))
        })

        # update the attributes of the node
        Convolution.update_node_stat(node, attrs)
        return cls.enabled
Exemplo n.º 5
0
    def extract(cls, node):
        attrs = tf_create_attrs(node, 2, 3)
        attrs.update({
            'op':
            __class__.op,
            'get_group':
            lambda node: node.group
            if 'group' in node and node.group is not None else node.in_node(0).
            shape[node.channel_dims] // node.kernel_shape[
                node.input_feature_channel],
            'get_output_feature_dim':
            lambda node: node.kernel_shape[node.output_feature_channel],
            'get_weights_permute':
            PermuteAttrs.Permutation(perm=int64_array([3, 2, 0, 1]),
                                     inv=int64_array([2, 3, 1, 0]))
        })

        # update the attributes of the node
        Convolution.update_node_stat(node, attrs)
        return cls.enabled
Exemplo n.º 6
0
 **valued_data('split_2_data1', np.zeros([3, 3, 4, 4])),
 **valued_data('split_2_data2', np.zeros([3, 3, 4, 4])),
 **valued_data('split_2_data3', np.zeros([3, 3, 4, 4])),
 **valued_data('split_2_data4', np.zeros([3, 3, 4, 4])),
 **regular_op_with_shaped_data(
     'conv2d_1', [1, 4, 8, 8], {
         'type':
         'Convolution',
         'channel_dims':
         np.array([1]),
         'pad':
         np.array([2, 2]),
         'stride':
         np.array([2, 2]),
         'get_weights_permute':
         PermuteAttrs.Permutation(perm=int64_array([3, 2, 0, 1]),
                                  inv=int64_array([2, 3, 1, 0])),
         'group':
         1,
         'output':
         4,
         'output_shape': [1, 4, 8, 8],
         'can_be_fused':
         True
     }),
 **regular_op_with_shaped_data(
     'conv2d_2', [1, 4, 8, 8], {
         'type': 'Convolution',
         'pad': np.array([2, 2]),
         'stride': np.array([2, 2]),
         'can_be_fused': True
     }),