Пример #1
0
    def extract(cls, node):
        # borders: leftBorder, topBorder, rightBorder, bottomBordes
        borders = onnx_attr(node,
                            'border',
                            'ints',
                            default=None,
                            dst_type=int64_array)
        scale = onnx_attr(node,
                          'scale',
                          'ints',
                          default=None,
                          dst_type=int64_array)

        # Crop reference: https://github.com/onnx/onnx/blob/master/docs/Operators.md#Crop
        if len(borders) != 4:
            log.error(
                'ONNX Crop layer {} should take exactly 4 borders instead of {}'
                .format(node.name, len(borders)))
            return False

        attrs = {'axis': int64_array([2, 3])}
        if scale is not None:
            attrs.update({
                'dim': scale,
                'offset': int64_array([borders[1], borders[0]])
            })
        else:
            attrs.update({
                'crop_begin': int64_array([borders[1], borders[0]]),
                'crop_end': int64_array([borders[3], borders[2]])
            })

        Crop.update_node_stat(node, attrs)
        return CropFrontExtractor.enabled
Пример #2
0
 def extract(cls, node):
     attrs = get_mxnet_layer_attrs(node.symbol_dict)
     offset = attrs.tuple("offset", int, ())
     axis = attrs.int("num_args", 0)
     node_attrs = {
         'axis': axis,
         'offset': list(offset),
         'dim': None,
     }
     Crop.update_node_stat(node, node_attrs)
     return cls.enabled
Пример #3
0
 def extract(cls, node):
     proto_layer = node.pb
     param = proto_layer.crop_param
     mapping_rule = {
         'axis': param.axis,
         'offset': param.offset,
         'dim': None,  # set in infer
         'infer': crop_infer
     }
     # update the attributes of the node
     Crop.update_node_stat(node, mapping_rule)
     return cls.enabled
Пример #4
0
    def extract(cls, node):
        pb = node.parameters

        mapping_rule = {
            'dim': pb['dim'],
            'offset': pb['offset'],
            'axis': pb['axis'],
            'layout': 'NCHW'
        }

        Crop.update_node_stat(node, attrs=mapping_rule)
        return cls.enabled