def __init__(self, kernel_size=1, stride=1, pad_mode="valid"): super(AvgPool2d, self).__init__(kernel_size, stride, pad_mode) self.avg_pool = P.AvgPool(ksize=self.kernel_size, strides=self.stride, padding=self.pad_mode)
def __init__(self, kernel_size=1, stride=1, pad_mode="valid", data_format="NCHW"): super(AvgPool2d, self).__init__(kernel_size, stride, pad_mode, data_format) self.avg_pool = P.AvgPool(ksize=self.kernel_size, strides=self.stride, padding=self.pad_mode, data_format=self.format)
def __init__(self, kernel_size=1, stride=1, pad_mode="valid"): super(AvgPool1d, self).__init__(kernel_size, stride, pad_mode) validator.check_value_type('kernel_size', kernel_size, [int], self.cls_name) validator.check_value_type('stride', stride, [int], self.cls_name) self.pad_mode = validator.check_string('pad_mode', pad_mode.upper(), ['VALID', 'SAME'], self.cls_name) validator.check_integer("kernel_size", kernel_size, 1, Rel.GE, self.cls_name) validator.check_integer("stride", stride, 1, Rel.GE, self.cls_name) self.kernel_size = (1, kernel_size) self.stride = (1, stride) self.avg_pool = P.AvgPool(ksize=self.kernel_size, strides=self.stride, padding=self.pad_mode) self.shape = F.shape self.reduce_mean = P.ReduceMean(keep_dims=True) self.slice = P.Slice() self.expand = P.ExpandDims()
def __init__(self, block, layer_nums, in_channels, out_channels, strides, num_classes): super(ResNet, self).__init__() if not len(layer_nums) == len(in_channels) == len(out_channels) == 4: raise ValueError("the length of layer_num, in_channels, out_channels list must be 4!") input_data_channel = 4 if format_ == "NCHW": input_data_channel = 3 self.conv1 = _conv7x7(input_data_channel, 64, stride=2) self.bn1 = _bn(64) self.relu = P.ReLU() self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, pad_mode="same", data_format=format_) self.layer1 = self._make_layer(block, layer_nums[0], in_channel=in_channels[0], out_channel=out_channels[0], stride=strides[0]) self.layer2 = self._make_layer(block, layer_nums[1], in_channel=in_channels[1], out_channel=out_channels[1], stride=strides[1]) self.layer3 = self._make_layer(block, layer_nums[2], in_channel=in_channels[2], out_channel=out_channels[2], stride=strides[2]) self.layer4 = self._make_layer(block, layer_nums[3], in_channel=in_channels[3], out_channel=out_channels[3], stride=strides[3]) self.avg_pool = P.AvgPool(7, 1, data_format=format_) self.flatten = nn.Flatten() self.end_point = _fc(out_channels[3], num_classes)
def __init__(self, kernel_size=1, stride=1, pad_mode="VALID", padding=0): avg_pool = P.AvgPool(ksize=kernel_size, strides=stride, padding=pad_mode) super(AvgPool2d, self).__init__(kernel_size, stride, pad_mode, padding, avg_pool)
'skip': ['backward']}), ('Sigmoid', { 'block': P.Sigmoid(), 'desc_inputs': [[1, 3, 4, 4]], 'desc_bprop': [[1, 3, 4, 4]]}), ('MaxPool', { 'block': P.MaxPool(ksize=(2, 2), strides=(2, 2), padding="VALID"), 'desc_inputs': [[100, 3, 28, 28]], 'desc_bprop': [[100, 3, 14, 14]]}), ('MaxPoolGrad', { 'block': G.MaxPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"), 'desc_inputs': [[3, 4, 6, 6], [3, 4, 3, 3], [3, 4, 3, 3]], 'desc_bprop': [[3, 4, 6, 6]], 'skip': ['backward']}), ('AvgPool', { 'block': P.AvgPool(ksize=(2, 2), strides=(2, 2), padding="VALID"), 'desc_inputs': [[100, 3, 28, 28]], 'desc_bprop': [[100, 3, 14, 14]]}), ('AvgPoolGrad', { 'block': G.AvgPoolGrad(ksize=(2, 2), strides=(2, 2), padding="VALID"), 'desc_const': [(3, 4, 6, 6)], 'const_first': True, 'desc_inputs': [[3, 4, 6, 6]], 'desc_bprop': [[3, 4, 6, 6]], 'skip': ['backward']}), ('MaxPoolWithArgmax', { 'block': P.MaxPoolWithArgmax(ksize=2, strides=2), 'desc_inputs': [[128, 32, 32, 64]], 'desc_bprop': [[128, 32, 8, 16], [128, 32, 8, 16]]}), ('SoftmaxCrossEntropyWithLogits', { 'block': P.SoftmaxCrossEntropyWithLogits(),
'desc_inputs': [Tensor(np.ones([1, 1, 32]).astype(np.float32))], 'skip': ['backward'] }), # rank of x is not 4 ('MaxPool2', { 'block': (P.MaxPool(ksize=50, strides=1), { 'exception': ValueError, 'error_keywords': ['MaxPool'] }), 'desc_inputs': [Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))], 'skip': ['backward'] }), # input is scalar ('AvgPool0', { 'block': (P.AvgPool(), { 'exception': TypeError, 'error_keywords': ['AvgPool'] }), 'desc_inputs': [5.0], 'skip': ['backward'] }), # rank of x is not 4 ('AvgPool1', { 'block': (P.AvgPool(), { 'exception': ValueError, 'error_keywords': ['AvgPool'] }), 'desc_inputs': [Tensor(np.ones([1, 1, 32]).astype(np.float32))], 'skip': ['backward'] }),