def extract(cls, node): pb = node.parameters collect_until_token(pb, b'<PoolSize>') kernel = read_binary_integer32_token(pb) tag = find_next_tag(pb) if tag == '<PoolStep>': read_placeholder(pb, 1) stride = read_binary_integer32_token(pb) pool_step = stride pool_stride = read_token_value(pb, b'<PoolStride>') elif tag == '<PoolStride>': stride = 1 pool_step = None read_placeholder(pb, 1) pool_stride = read_binary_integer32_token(pb) else: raise Error('Can not extract parameters for {}'.format(node)) mapping_rule = { 'window': np.array([1, 1, 1, kernel], dtype=np.int64), 'stride': np.array([1, 1, stride, stride], dtype=np.int64), 'pool_stride': pool_stride, 'pool_step': pool_step, 'pad': np.array([[0, 0], [0, 0], [0, 0], [0, 0]], dtype=np.int64), 'pad_spatial_shape': np.array([[0, 0], [0, 0]], dtype=np.int64), 'pool_method': 'max', } mapping_rule.update(layout_attrs()) Pooling.update_node_stat(node, mapping_rule) return cls.enabled
def infer(cls, node: Node): input_shape = node.in_node(0).shape input_h = input_shape[2] input_w = input_shape[3] output_h = node.output_size[0] output_w = node.output_size[1] stride_h = input_h // output_h stride_w = input_w // output_w kernel_h = input_h - (output_h - 1) * stride_h kernel_w = input_w - (output_w - 1) * stride_w data = { 'window': int64_array([1, 1, kernel_h, kernel_w]), 'stride': int64_array([1, 1, stride_h, stride_w]), 'pad': int64_array([[0, 0], [0, 0], [0, 0], [0, 0]]), 'pad_spatial_shape': int64_array([[0, 0], [0, 0]]), 'pool_method': 'avg', 'exclude_pad': 'false', 'output_spatial_shape': None, 'spatial_dims': None, 'channel_dims': int64_array([1]), 'batch_dims': int64_array([0]), 'layout': 'NCHW', 'rounding_type': 'floor', 'pooling_convention': 'valid' } # update the attributes of the node Pooling.update_node_stat(node, data) Pooling.infer(node)
def extract(cls, node): # Extract pads attribute final_pads = get_pads(node.module) # Extract strides attribute strides = [node.module.stride, node.module.stride] final_strides = np.array([1, 1, *strides], dtype=np.int64) kernel_shape = [node.module.kernel_size, node.module.kernel_size] final_kernel_shape = np.array([1, 1, *kernel_shape], dtype=np.int64) attrs = { 'op': node.op, 'window': final_kernel_shape, 'stride': final_strides, 'pad': final_pads, 'pool_method': 'avg', 'exclude_pad': 'false', 'channel_dims': np.array([1], dtype=np.int64), 'batch_dims': np.array([0], dtype=np.int64), 'layout': 'NCHW', } # update the attributes of the node Pooling.update_node_stat(node, attrs) return cls.enabled
def extract(cls, node): # Extract pads attribute pads = np.array([node.module.padding, node.module.padding], dtype=np.int64).reshape(1, 2) pads = np.repeat(pads, 2, axis=0) final_pads = np.array([[0, 0], [0, 0], *pads], dtype=np.int64) # Extract strides attribute strides = [node.module.stride, node.module.stride] final_strides = np.array([1, 1, *strides], dtype=np.int64) kernel_shape = [node.module.kernel_size, node.module.kernel_size] final_kernel_shape = np.array([1, 1, *kernel_shape], dtype=np.int64) attrs = { 'op': node.op, 'window': final_kernel_shape, 'stride': final_strides, 'pad': final_pads, 'pool_method': 'max', 'channel_dims': np.array([1], dtype=np.int64), 'batch_dims': np.array([0], dtype=np.int64), 'layout': 'NCHW', } # update the attributes of the node Pooling.update_node_stat(node, attrs) return cls.enabled
def extract(cls, node): attrs = common_onnx_pool_extractor(node) attrs.update({'pooling_convention': 'full', 'global_pool': True, }) Pooling.update_node_stat(node, attrs) return cls.enabled
def extract(node): attrs = get_mxnet_layer_attrs(node.symbol_dict) kernel = attrs.tuple("kernel", int, None) stride = attrs.tuple("stride", int, tuple(np.ones(len(kernel), dtype=np.int64))) padding = attrs.tuple("pad", int, tuple(np.zeros(len(kernel), dtype=np.int64))) method = attrs.str("pool_type", None) rt = 'floor' data = { 'window': np.array([1, 1, *[k for k in kernel]], dtype=np.int64), 'stride': np.array([1, 1, *[s for s in stride]], dtype=np.int64), 'pad': np.array([[0, 0], [0, 0], *[[pad, pad] for pad in padding]], dtype=np.int64), 'pad_spatial_shape': np.array([[pad, pad] for pad in padding], dtype=np.int64), 'pool_method': method, 'exclude_pad': 'false', 'output_spatial_shape': None, 'spatial_dims': None, 'channel_dims': np.array([1], dtype=np.int64), 'batch_dims': np.array([0], dtype=np.int64), 'layout': 'NCHW', 'rounding_type': rt, } pooling_conv = attrs.str("pooling_convention", 'valid') if pooling_conv: data["pooling_convention"] = pooling_conv if pooling_conv == 'full': data["rounding_type"] = 'ceil' global_pool = attrs.bool("global_pool", False) if global_pool: data["global_pool"] = global_pool # update the attributes of the node Pooling.update_node_stat(node, data) return __class__.enabled
def extract(cls, node): attrs = create_pooling_attrs(node, 'avg') attrs.update({'op': __class__.op}) # update the attributes of the node Pooling.update_node_stat(node, attrs) return cls.enabled
def extract(node): attrs = common_onnx_pool_extractor(node) Pooling.update_node_stat(node, attrs) return __class__.enabled
def extract(cls, node): attrs = common_onnx_pool_extractor(node) Pooling.update_node_stat(node, attrs) return cls.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.pooling_param method = 'max' exclude_pad = True kernel = [0, 0] stride = [1, 1] padding = [0, 0] global_pooling = False if hasattr(param, 'global_pooling') and param.global_pooling: global_pooling = param.global_pooling else: kernel = get_spatial_attr(kernel, 'kernel_size', 'kernel', param) padding = get_spatial_attr(padding, 'pad', 'pad', param) stride = get_spatial_attr(stride, 'stride', 'stride', param) if param.pool == 0: method = 'max' exclude_pad = True elif param.pool == 1: method = 'avg' exclude_pad = False else: raise ValueError('Unknown Pooling Method!') pooling_convention = 'full' # for Caffe rounding type should be ceil rt = 'ceil' if hasattr(param, 'ceil_mode') and not param.ceil_mode: # If pooling has ceil_mode and ceil_mode is False using floor for rounding shapes in partial_infer pooling_convention = 'valid' rt = 'floor' attrs = { 'window': np.array([1, 1, kernel[1], kernel[0]], dtype=np.int64), 'stride': np.array([1, 1, stride[1], stride[0]], dtype=np.int64), 'pad': np.array([[0, 0], [0, 0], [padding[1], padding[1]], [padding[0], padding[0]]], dtype=np.int64), 'pad_spatial_shape': np.array([[padding[1], padding[1]], [padding[0], padding[0]]], dtype=np.int64), 'pool_method': method, 'exclude_pad': exclude_pad, 'global_pool': global_pooling, 'output_spatial_shape': None, 'rounding_type': rt } attrs.update(layout_attrs()) attrs['pooling_convention'] = pooling_convention # update the attributes of the node Pooling.update_node_stat(node, attrs) return cls.enabled