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 = Add()
def __init__(self, inp, oup, stride, expand_ratio): super(InvertedResidual, self).__init__() self.stride = stride assert stride in [1, 2] hidden_dim = int(round(inp * expand_ratio)) self.use_res_connect = self.stride == 1 and inp == oup layers = [] if expand_ratio != 1: # pw layers.append(ConvBNReLU(inp, hidden_dim, kernel_size=1)) layers.extend([ # dw ConvBNReLU(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).add_flags_recursive(fp32=True) ]) self.conv = nn.SequentialCell(layers) self.add = Add() 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 = Add() z = tensor_add(x, y) assert np.all(z.asnumpy() - (x.asnumpy() + y.asnumpy()) < 0.0001)
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().shard(strategy_no_weight) self.relu2 = P.ReLU().shard(strategy_no_weight) self.relu3 = P.ReLU().shard(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 = Add().shard(strategy_add)
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.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 = Add()
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 = 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 = 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 = Add()
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 = Add() self.cast = P.Cast() self.relu2 = P.ReLU()
def __init__(self): super(Block1, self).__init__() self.bk1_conv0 = conv3x3(64, 64, stride=1, padding=1) self.bk1_bn0 = bn_with_initialize(64) self.bk1_relu0 = P.ReLU() self.bk1_conv1 = conv3x3(64, 64, stride=1, padding=1) self.bk1_bn1 = bn_with_initialize(64) self.bk1_conv2 = conv1x1(64, 64, stride=1, padding=0) self.bk1_bn2 = bn_with_initialize(64) self.bk1_relu1 = P.ReLU() self.bk1_conv3 = conv3x3(64, 64, stride=1, padding=1) self.bk1_bn3 = bn_with_initialize(64) self.bk1_relu3 = P.ReLU() self.bk1_conv4 = conv3x3(64, 64, stride=1, padding=1) self.bk1_bn4 = bn_with_initialize(64) self.bk1_relu4 = P.ReLU() self.cast = P.Cast() self.add = 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 = Add()
def __init__(self): super(Net, self).__init__() self.add = Add()
def __init__(self): super(TensorAddNetMe, self).__init__() self.relu = ReLU() self.add = Add()
def __init__(self, encode_dim): super(EncoderNet, self).__init__() self._encode_dim = encode_dim self.add = Add()