def common_backpropdata_extender(op: Node):
    for attr in ['strides', 'output_padding', 'pads_begin', 'pads_end', 'dilations']:
        Extender.attr_to_list(op, attr)

    if op.has_valid('output_padding'):
        op.output_padding = int64_array([0, 0] + op.output_padding)

    dim = len(op.strides)

    if op.has_valid('pads_begin') and op.has_valid('pads_end'):
        pad = [[0, 0], [0, 0]]
        pad.extend([[op.pads_begin[i], op.pads_end[i]] for i in range(dim)])

        op['pad'] = int64_array(pad)

    op['spatial_dims'] = [i + 2 for i in range(dim)]

    if not op.has_valid('dilations'):
        op['dilations'] = [1 for _ in range(dim)]
    if not op.has_valid('strides'):
        op['strides'] = [1 for _ in range(dim)]

    op['dilation'] = int64_array([1, 1] + op.dilations)
    op['stride'] = int64_array([1, 1] + op.strides)

    op['infer'] = backpropdata_infer
Esempio n. 2
0
    def extend(op: Node):
        if not op.has_valid('activations'):
            op['activations'] = None

        mark_input_bins(op, start_port=2)

        op['need_copy_input_blobs'] = True
Esempio n. 3
0
    def extend(op: Node):
        for attr in [
                'strides', 'dilations', 'pads_begin', 'pads_end',
                'output_padding'
        ]:
            Extender.attr_to_list(op, attr)

        op['stride'] = int64_array([1, 1] + op.strides)
        op['dilation'] = int64_array([1, 1] + op.dilations)

        op['batch_dims'] = int64_array([0])
        op['channel_dims'] = int64_array([1])

        if op.has_valid('output_padding'):
            op.output_padding = int64_array([0, 0] + op.output_padding)

        # Be VERY careful with these attributes!
        op['input_feature_channel'] = 1
        op['output_feature_channel'] = 0

        dim = len(op.pads_begin)

        assert dim in (1, 2, 3), '{}D Convolution not supported!'.format(dim)

        pad = [[0, 0], [0, 0]]
        pad.extend([[op.pads_begin[i], op.pads_end[i]] for i in range(dim)])

        op['pad'] = int64_array(pad)

        op['spatial_dims'] = [i + 2 for i in range(dim)]
Esempio n. 4
0
 def attr_restore(node: Node, attribute: str, value=None):
     # Function to restore some specific attr for PriorBox & PriorBoxClustered layers
     if not node.has_valid(attribute):
         node[attribute] = [] if value is None else [value]
     if isinstance(node[attribute], str):
         node[attribute] = []
     else:
         Extender.attr_to_list(node, attribute)
 def extend(op: Node):
     assert op.has_valid(
         'element_type'
     ), 'Parameter node {} has missed element_type attr!'.format(op.name)
     op['data_type'] = destination_type_to_np_data_type(op.element_type)
     if op.shape == '':
         op.shape = int64_array([])
     else:
         Extender.attr_to_list(op, 'shape')
         if -1 in op.shape:
             op.shape = shape_array([
                 d if d != -1 else dynamic_dimension_value for d in op.shape
             ])
Esempio n. 6
0
 def extend(op: Node):
     assert op.has_valid(
         'element_type'
     ), 'Parameter node {} has missed element_type attr!'.format(op.name)
     op['data_type'] = destination_type_to_np_data_type(op.element_type)
     if op.shape == '':
         op.shape = int64_array([])
     else:
         Extender.attr_to_list(op, 'shape')
         for i, dim in enumerate(op.shape):
             if dim == -1 or (isinstance(dim, str) and ".." in dim):
                 op.shape[i] = -1
         op.shape = shape_array(
             [d if d != -1 else dynamic_dimension_value for d in op.shape])
Esempio n. 7
0
    def extend(op: Node):
        assert op.has_valid(
            'element_type'
        ), 'Parameter node {} has missed element_type attr!'.format(op.name)
        op['data_type'] = destination_type_to_np_data_type(op.element_type)
        if op.shape == '':
            op.shape = int64_array([])
        else:
            Extender.attr_to_list(op, 'shape')
            shape = op.shape.copy()
            has_shapes_with_boundaries = False
            for i, dim in enumerate(op.shape):
                if dim == -1 or (isinstance(dim, str) and ".." in dim):
                    shape[i] = -1
                    if ".." in dim:
                        has_shapes_with_boundaries = True
            shape = shape_array([
                d if d not in [-1, '?'] else dynamic_dimension_value
                for d in shape
            ])

            if has_shapes_with_boundaries:
                shape_list = []
                for i, dim in enumerate(op.shape):
                    if not isinstance(dim, str):
                        shape_list.append(dim)
                    else:
                        shape_list.append(parse_dimension(dim))

                # This value is used only for serialization of partial shapes with boundaries
                # for Parameter node.
                # 'user_shape' is not used in shape inference, as propagation of partial shapes with boundaries
                # is not implemented in MO.
                op['user_shape'] = tuple(shape_list)

            # If 'user_shape' is not set, 'shape' attribute is used for serialization.
            # 'shape' is also used for shape inference.
            op.shape = shape
Esempio n. 8
0
 def extend(op: Node):
     if op.has_valid('output_type'):
         op['output_type'] = destination_type_to_np_data_type(
             op.output_type)
Esempio n. 9
0
 def attr_to_list(node: Node, attribute: str):
     if not node.has_valid(attribute):
         log.warning('Attribute {} missed in node {} with type {}!'.format(
             attribute, node.soft_get('name'), node.soft_get('type')))
     elif not isinstance(node[attribute], list):
         node[attribute] = [node[attribute]]
Esempio n. 10
0
 def extend(op: Node):
     if op.out_port(0).disconnected():
         op['remove_values_output'] = True
     if op.has_valid('index_element_type'):
         op['index_element_type'] = destination_type_to_np_data_type(
             op.index_element_type)
 def extend(op: Node):
     if op.has_valid('classes_index_type'):
         op['classes_index_type'] = destination_type_to_np_data_type(op.classes_index_type)
     if op.has_valid('sequence_length_type'):
         op['sequence_length_type'] = destination_type_to_np_data_type(op.sequence_length_type)
Esempio n. 12
0
 def extend(op: Node):
     if not op.has_valid('activations'):
         op['activations'] = None
Esempio n. 13
0
 def extend(op: Node):
     if not op.has_valid('activations'):
         op['activations'] = None
     op['infer'] = Extender.use_shapes_from_ir