def __init__(self, in_channels, out_channels, stride=1, down_sample=None, base_width=64, groups=1, use_se=False, **kwargs): super(Bottleneck, self).__init__() width = int(out_channels * (base_width / 64.0)) * groups self.groups = groups self.conv1 = conv1x1(in_channels, width, stride=1) self.bn1 = nn.BatchNorm2d(width) self.relu = P.ReLU() self.conv3x3s = nn.CellList() self.conv2 = GroupConv(width, width, 3, stride, pad=1, groups=groups) self.op_split = Split(axis=1, output_num=self.groups) self.op_concat = Concat(axis=1) self.bn2 = nn.BatchNorm2d(width) self.conv3 = conv1x1(width, out_channels * self.expansion, stride=1) self.bn3 = nn.BatchNorm2d(out_channels * self.expansion) self.use_se = use_se if self.use_se: self.se = SEBlock(out_channels * self.expansion) self.down_sample_flag = False if down_sample is not None: self.down_sample = down_sample self.down_sample_flag = True self.cast = P.Cast() self.add = TensorAdd()
def __init__(self, in_channels, out_channels, stride=1, down_sample=None, use_se=False, platform="Ascend", **kwargs): super(BasicBlock, self).__init__() self.conv1 = conv3x3(in_channels, out_channels, stride=stride) self.bn1 = nn.BatchNorm2d(out_channels) self.relu = P.ReLU() self.conv2 = conv3x3(out_channels, out_channels, stride=1) self.bn2 = nn.BatchNorm2d(out_channels) self.use_se = use_se if self.use_se: self.se = SEBlock(out_channels) self.down_sample_flag = False if down_sample is not None: self.down_sample = down_sample self.down_sample_flag = True self.add = TensorAdd()
def __init__(self, device_target, inp, oup, stride, expand_ratio): super(InvertedResidual, self).__init__() assert stride in [1, 2] hidden_dim = int(round(inp * expand_ratio)) self.use_res_connect = stride == 1 and inp == oup layers = [] if expand_ratio != 1: layers.append( ConvBNReLU(device_target, inp, hidden_dim, kernel_size=1)) layers.extend([ # dw ConvBNReLU(device_target, hidden_dim, hidden_dim, stride=stride, groups=hidden_dim), # pw-linear nn.Conv2d(hidden_dim, oup, kernel_size=1, stride=1, has_bias=False), nn.BatchNorm2d(oup), ]) self.conv = nn.SequentialCell(layers) self.add = TensorAdd() self.cast = P.Cast()
def test_tensor_add(): x = Tensor(np.ones([1, 3, 4, 4]).astype(np.float32)) y = Tensor(np.ones([1, 3, 4, 4]).astype(np.float32)) tensor_add = TensorAdd() z = tensor_add(x, y) assert np.all(z.asnumpy() - (x.asnumpy() + y.asnumpy()) < 0.0001)
def __init__(self, inplanes, planes, stride=1, downsample=None, use_se=1, pre_bn=1, use_inference=0, act_type='relu'): super(IRBlock, self).__init__() if pre_bn == 1: self.bn1 = bn_with_initialize(inplanes, use_inference=use_inference) else: self.bn1 = Cut() self.conv1 = conv3x3(inplanes, planes, stride=1) self.bn2 = bn_with_initialize(planes, use_inference=use_inference) self.act_layer = nn.PReLU(planes) if act_type == 'prelu' else P.ReLU() self.conv2 = conv3x3(planes, planes, stride=stride) self.bn3 = bn_with_initialize(planes, use_inference=use_inference) if downsample is None: self.downsample = Cut() else: self.downsample = downsample self.use_se = use_se if use_se == 1: self.se = SEBlock(planes, act_type=act_type) self.add = TensorAdd() self.cast = P.Cast()
def __init__(self, channels): super(BaseBlock, self).__init__() self.conv1 = conv3x3(channels, channels, stride=1, padding=1, bias=False) self.bn1 = bn_with_initialize(channels) self.relu1 = P.ReLU() self.conv2 = conv3x3(channels, channels, stride=1, padding=1, bias=False) self.bn2 = bn_with_initialize(channels) self.relu2 = P.ReLU() self.cast = P.Cast() self.add = TensorAdd()
def __init__(self, in_channels, out_channels, stride=1, down_sample=None, base_width=64, groups=1, use_se=False, platform="Ascend", **kwargs): super(Bottleneck, self).__init__() width = int(out_channels * (base_width / 64.0)) * groups self.groups = groups self.conv1 = conv1x1(in_channels, width, stride=1) self.bn1 = nn.BatchNorm2d(width) self.relu = P.ReLU() self.conv3x3s = nn.CellList() if platform == "GPU": self.conv2 = nn.Conv2d(width, width, 3, stride, pad_mode='pad', padding=1, group=groups) else: self.conv2 = GroupConv(width, width, 3, stride, pad=1, groups=groups) self.bn2 = nn.BatchNorm2d(width) self.conv3 = conv1x1(width, out_channels * self.expansion, stride=1) self.bn3 = nn.BatchNorm2d(out_channels * self.expansion) self.use_se = use_se if self.use_se: self.se = SEBlock(out_channels * self.expansion) self.down_sample_flag = False if down_sample is not None: self.down_sample = down_sample self.down_sample_flag = True self.cast = P.Cast() self.add = TensorAdd()
def __init__(self, in_channels, out_channels, stride=1, down_sample=False): super(ResidualBlock, self).__init__() out_chls = out_channels // self.expansion self.conv1 = conv1x1(in_channels, out_chls, stride=1, padding=0) self.bn1 = bn_with_initialize(out_chls) self.conv2 = conv3x3(out_chls, out_chls, stride=stride, padding=1) self.bn2 = bn_with_initialize(out_chls) self.conv3 = conv1x1(out_chls, out_channels, stride=1, padding=0) self.bn3 = bn_with_initialize_last(out_channels) self.relu = P.ReLU() self.add = TensorAdd()
def __init__(self, inplanes, planes, stride=1, downsample=None): super(IRBlock, self).__init__() self.conv1 = conv3x3(inplanes, planes, stride=stride) self.bn1 = bn_with_initialize(planes) self.relu1 = P.ReLU() self.conv2 = conv3x3(planes, planes, stride=1) self.bn2 = bn_with_initialize(planes) if downsample is None: self.downsample = Cut() else: self.downsample = downsample self.add = TensorAdd() self.cast = P.Cast() self.relu2 = P.ReLU()
def __init__(self, in_channels, out_channels, stride=1): super(ResidualBlock, self).__init__() out_chls = out_channels // self.expansion self.conv1 = conv1x1(in_channels, out_chls, stride=1) self.bn1 = bn_with_initialize(out_chls) self.conv2 = conv3x3(out_chls, out_chls, stride=stride) self.bn2 = bn_with_initialize(out_chls) self.conv3 = conv1x1(out_chls, out_channels, stride=1) self.bn3 = bn_with_initialize_last(out_channels) self.relu1 = P.ReLU().shard(strategy_no_weight) self.relu2 = P.ReLU().shard(strategy_no_weight) self.relu3 = P.ReLU().shard(strategy_no_weight) self.add = TensorAdd().shard(strategy_add)
def __init__(self, in_channels, out_channels, stride=1, down_sample=False): super(ResidualBlock, self).__init__() out_chls = out_channels // self.expansion self.conv1 = conv1x1(in_channels, out_chls, stride=1, padding=0) self.bn1 = nn.BatchNorm2d(out_chls) self.conv2 = conv3x3(out_chls, out_chls, stride=stride, padding=1) self.bn2 = nn.BatchNorm2d(out_chls) self.conv3 = conv1x1(out_chls, out_channels, stride=1, padding=0) self.bn3 = nn.BatchNorm2d(out_channels) self.relu = nn.ReLU() self.downsample = down_sample self.conv_down_sample = conv1x1(in_channels, out_channels, stride=stride, padding=0) self.bn_down_sample = nn.BatchNorm2d(out_channels) self.add = TensorAdd()
def __init__(self, in_channels, out_channels, stride=1, down_sample=False): super(ResidualBlockWithDown, self).__init__() out_chls = out_channels // self.expansion self.conv1 = conv1x1(in_channels, out_chls, stride=1) self.bn1 = bn_with_initialize(out_chls) self.conv2 = conv3x3(out_chls, out_chls, stride=stride) self.bn2 = bn_with_initialize(out_chls) self.conv3 = conv1x1(out_chls, out_channels, stride=1) self.bn3 = bn_with_initialize_last(out_channels) self.relu1 = P.ReLU().set_strategy(strategy_no_weight) self.relu2 = P.ReLU().set_strategy(strategy_no_weight) self.relu3 = P.ReLU().set_strategy(strategy_no_weight) self.down_sample = down_sample self.conv_down_sample = conv1x1(in_channels, out_channels, stride=stride) self.bn_down_sample = bn_with_initialize(out_channels) self.add = TensorAdd().set_strategy(strategy_add)
def __init__(self): super(Net, self).__init__() self.add = TensorAdd()
def __init__(self, encode_dim): super(EncoderNet, self).__init__() self._encode_dim = encode_dim self.add = TensorAdd()
def __init__(self): super(TensorAddNetMe, self).__init__() self.relu = ReLU() self.add = TensorAdd()