def constructor(self, in_channels=256, feat_channels=256, num_classes=2): """Create rpn Search Space.""" anchor_scales = [8, 16, 32] anchor_ratios = [0.5, 1.0, 2.0] num_anchors = len(anchor_ratios) * len(anchor_scales) if feat_channels > 0: conv = op.Conv2d(in_channels=in_channels, out_channels=feat_channels, kernel_size=3, padding=1) relu = op.ReLU(inplace=True) rpn_cls_conv = op.Conv2d(in_channels=feat_channels, out_channels=num_anchors * num_classes, kernel_size=1) rpn_reg_conv = op.Conv2d(in_channels=feat_channels, out_channels=num_anchors * 4, kernel_size=1) rpn_cls = Sequential(conv, relu, rpn_cls_conv) rpn_reg = Sequential(conv, relu, rpn_reg_conv) else: rpn_cls = op.Conv2d(in_channels=in_channels, out_channels=num_anchors * num_classes, kernel_size=1) rpn_reg = op.Conv2d(in_channels=in_channels, out_channels=num_anchors * 4, kernel_size=1) self.rpn = Tuple(Map(rpn_cls), Map(rpn_reg))
def constructor(self, arch, G0, kSize): """Create ERDBLayer. :param arch: arch :type arch: dict :param G0: G0 :type G0: G0 :param kSize: kSize :type kSize: int """ b_in_chan = G0 b_out_chan = 0 Conc_all = 0 ERDBs = [] for i in range(len(arch)): name = arch[i] key = name.split('_') if i > 0: b_in_chan = b_out_chan b_conv_num = int(key[1]) b_grow_rat = int(key[2]) b_out_chan = int(key[3]) Conc_all += b_out_chan if key[0] == 'S': ERDBs.append( Shrink_RDB(InChannel=b_in_chan, OutChannel=b_out_chan, growRate=b_grow_rat, nConvLayers=b_conv_num)) elif key[0] == 'G': ERDBs.append( Group_RDB(InChannel=b_in_chan, OutChannel=b_out_chan, growRate=b_grow_rat, nConvLayers=b_conv_num)) elif key[0] == 'C': ERDBs.append( Cont_RDB(InChannel=b_in_chan, OutChannel=b_out_chan, growRate=b_grow_rat, nConvLayers=b_conv_num)) self.ERBD = Append(*tuple(ERDBs)) self.cat = Esrn_Cat() self.GFF1 = op.Conv2d(in_channels=Conc_all, out_channels=G0, kernel_size=1, stride=1, padding=0) self.GFF2 = op.Conv2d(in_channels=G0, out_channels=G0, kernel_size=kSize, stride=1, padding=(kSize - 1) // 2)
def constructor(self, InChannel, OutChannel, growRate, nConvLayers, kSize=3): """Create InConv_Group Block. :param InChannel: channel number of input :type InChannel: int :param OutChannel: channel number of output :type OutChannel: int :param growRate: growth rate of block :type growRate: int :param nConvLayers: the number of convlution layer :type nConvLayers: int :param kSize: kernel size of convolution operation :type kSize: int """ if InChannel != growRate: self.InConv = op.Conv2d(in_channels=InChannel, out_channels=growRate, kernel_size=1, stride=1, padding=0) self.make_conv(nConvLayers, growRate, OutChannel) else: self.make_conv(nConvLayers, growRate, OutChannel)
def constructor(self, inChannels, growRate, sh_groups, conv_groups, kSize=3): """Create Block_Base Block. :param inChannels: channel number of input :type inChannels: int :param growRate: growth rate of block :type growRate: int :param sh_groups: group number of shuffle operation :type sh_groups: int :param conv_groups: group number of convolution operation :type conv_groups: int :param kSize: kernel size of convolution operation :type kSize: int """ self.channel_shuffle = ChannelShuffle(sh_groups) self.conv = op.Conv2d(in_channels=inChannels, out_channels=growRate, kernel_size=kSize, stride=1, padding=(kSize - 1) // 2, groups=conv_groups) self.relu = op.ReLU()
def constructor(self, InChannel, OutChannel, growRate, nConvLayers, kSize=3): """Create Cont_Seq Block. :param InChannel: channel number of input :type InChannel: int :param OutChannel: channel number of output :type OutChannel: int :param growRate: growth rate of block :type growRate: int :param nConvLayers: the number of convlution layer :type nConvLayers: int :param kSize: kernel size of convolution operation :type kSize: int """ if InChannel != growRate: self.InConv = op.Conv2d(in_channels=InChannel, out_channels=growRate, kernel_size=1, stride=1, padding=0) self.pool = op.AvgPool2d(kernel_size=2, stride=2) else: self.pool = op.AvgPool2d(kernel_size=2, stride=2) self.cont_conv = op.Cont_Conv(InChannel=InChannel, OutChannel=OutChannel, growRate=growRate, nConvLayers=nConvLayers, kSize=kSize)
def constructor(self, scale, G0, kSize, n_colors): """Create UPNet Block. :param scale: scale :type scale: int :param G0: G0 :type G0: G0 :param kSize: kSize :type kSize: int :param n_colors: n_colors :type n_colors: int """ if scale == 2 or scale == 3: self.conv = op.Conv2d(in_channels=G0, out_channels=G0 * 3, kernel_size=kSize, stride=1, padding=(kSize - 1) // 2) self.pixelshuffle = op.PixelShuffle(upscale_factor=scale) self.conv2 = op.Conv2d(in_channels=int(G0 * 3 / 4), out_channels=n_colors, kernel_size=kSize, stride=1, padding=(kSize - 1) // 2) elif scale == 4: self.conv = op.Conv2d(in_channels=G0, out_channels=G0 * 4, kernel_size=kSize, stride=1, padding=(kSize - 1) // 2) self.pixelshuffle = op.PixelShuffle(upscale_factor=2) self.conv2 = op.Conv2d(in_channels=G0, out_channels=G0 * 4, kernel_size=kSize, stride=1, padding=(kSize - 1) // 2) self.pixelshuffle2 = op.PixelShuffle(upscale_factor=2) self.conv3 = op.Conv2d(in_channels=G0, out_channels=n_colors, kernel_size=kSize, stride=1, padding=(kSize - 1) // 2) else: raise ValueError("scale must be 2 or 3 or 4.")
def constructor(self, inp, oup, stride, kernel=3, expand_ratio=1): """Construct InvertedResidual class. :param inp: input channel :param oup: output channel :param stride: stride :param kernel: kernel :param expand_ratio: channel increase multiplier """ hidden_dim = round(inp * expand_ratio) conv = [] if expand_ratio > 1: conv = [ op.Conv2d(in_channels=inp, out_channels=hidden_dim, kernel_size=1, stride=1, padding=0, bias=False), op.BatchNorm2d(num_features=hidden_dim), op.ReLU6(inplace=True) ] conv = conv + [ op.Conv2d(in_channels=hidden_dim, out_channels=hidden_dim, kernel_size=kernel, stride=stride, padding=kernel // 2, groups=hidden_dim, bias=False), op.BatchNorm2d(num_features=hidden_dim), op.ReLU6(inplace=True), op.Conv2d(in_channels=hidden_dim, out_channels=oup, kernel_size=1, stride=1, padding=0, bias=False), op.BatchNorm2d(num_features=oup) ] self.Conv = Sequential(*tuple(conv))
def constructor(self, InChannel, OutChannel, growRate, nConvLayers, kSize=3): """Create Cont_RDB Block. :param InChannel: channel number of input :type InChannel: int :param OutChannel: channel number of output :type OutChannel: int :param growRate: growth rate of block :type growRate: int :param nConvLayers: the number of convlution layer :type nConvLayers: int :param kSize: kernel size of convolution operation :type kSize: int """ cont_seq = Cont_Seq(InChannel=InChannel, OutChannel=OutChannel, growRate=growRate, nConvLayers=nConvLayers, kSize=kSize) if OutChannel == InChannel: self.merge = Add(cont_seq) elif OutChannel == growRate: InConv = op.Conv2d(in_channels=InChannel, out_channels=growRate, kernel_size=1, stride=1, padding=0) self.merge = Add(InConv, cont_seq) else: OutConv = op.Conv2d(in_channels=InChannel, out_channels=OutChannel, kernel_size=1, stride=1, padding=0) self.merge = Add(OutConv, cont_seq)
def __init__(self, init_plane): """Create InitialBlock layer. :param init_plane: input channel. :type init_plane: int """ super(InitialBlock, self).__init__(init_plane) self.conv = op.Conv2d(in_channels=3, out_channels=init_plane, kernel_size=7, stride=2, padding=3, bias=False) self.batch = op.BatchNorm2d(num_features=init_plane) self.relu = op.ReLU() self.maxpool2d = op.MaxPool2d(kernel_size=3, stride=2, padding=1)
def make_conv(self, nConvLayers, growRate, OutChannel): """Make Block_Base. :param OutChannel: channel number of output :type OutChannel: int :param growRate: growth rate of block :type growRate: int :param nConvLayers: the number of convlution layer :type nConvLayers: int """ convs = [] for c in range(nConvLayers): conv = Block_Base(inChannels=(c + 1) * growRate, growRate=growRate, sh_groups=c + 1, conv_groups=min(4, 2**int(math.log(c + 1, 2)))) cat = Concat(conv) convs.append(cat) self.seq = Sequential(*tuple(convs)) self.LFF = op.Conv2d(in_channels=(nConvLayers + 1) * growRate, out_channels=OutChannel, kernel_size=1, stride=1, padding=0)