Esempio n. 1
0
    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()
Esempio n. 2
0
    def __init__(self,
                 inchannel,
                 outchannel,
                 expansion,
                 groups,
                 base_width,
                 stride=1):
        """Create BottleConv layer.

        :param inchannel: input channel.
        :type inchannel: int
        :param outchannel: output channel.
        :type outchannel: int
        :param expansion: expansion
        :type expansion: int
        :param stride: the number to jump, default 1
        :type stride: int
        """
        super(BottleConv, self).__init__(inchannel,
                                         outchannel,
                                         groups,
                                         base_width,
                                         stride=1)
        outchannel = int(outchannel * (base_width / 64.)) * groups
        self.conv1 = conv1X1(inchannel=inchannel, outchannel=outchannel)
        self.batch1 = op.BatchNorm2d(num_features=outchannel)
        self.conv2 = conv3x3(inchannel=outchannel,
                             outchannel=outchannel,
                             groups=groups,
                             stride=stride)
        self.batch2 = op.BatchNorm2d(num_features=outchannel)
        self.conv3 = conv1X1(inchannel=outchannel,
                             outchannel=outchannel * expansion)
        self.batch3 = op.BatchNorm2d(num_features=outchannel * expansion)
        self.relu = op.ReLU()
Esempio n. 3
0
    def __init__(self,
                 inchannel,
                 outchannel,
                 groups=1,
                 base_width=64,
                 stride=1,
                 inner_plane=None):
        """Create BasicBlock layers.

        :param inchannel: input channel.
        :type inchannel: int
        :param outchannel: output channel.
        :type outchannel: int
        :param stride: the number to jump, default 1
        :type stride: int
        """
        super(BasicBlock, self).__init__(inchannel, outchannel, groups,
                                         base_width, stride, inner_plane)
        base_conv = BasicConv(inchannel=inchannel,
                              outchannel=outchannel,
                              stride=stride,
                              groups=groups,
                              base_width=base_width,
                              inner_plane=inner_plane)
        shortcut = ShortCut(inchannel=inchannel,
                            outchannel=outchannel,
                            expansion=self.expansion,
                            stride=stride)
        self.block = Add(base_conv, shortcut)
        self.relu = op.ReLU()
Esempio n. 4
0
 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))
Esempio n. 5
0
    def __init__(self, init_plane):
        """Create SmallInputInitialBlock layer.

        :param init_plane: input channel.
        :type init_plane: int
        """
        super(SmallInputInitialBlock, self).__init__(init_plane)
        self.conv = conv3x3(inchannel=3, outchannel=init_plane, stride=1)
        self.batch = op.BatchNorm2d(num_features=init_plane)
        self.relu = op.ReLU()
Esempio n. 6
0
    def __init__(self,
                 inchannel,
                 outchannel,
                 groups=1,
                 base_width=64,
                 stride=1,
                 inner_plane=None):
        """Create BasicConv layer.

        :param inchannel: input channel.
        :type inchannel: int
        :param outchannel: output channel.
        :type outchannel: int
        :param stride: the number to jump, default 1
        :type stride: int
        """
        super(BasicConv, self).__init__(inchannel, outchannel, groups,
                                        base_width, stride, inner_plane)
        if inner_plane is None:
            if groups != 1 or base_width != 64:
                raise ValueError(
                    "BasicBlock only supports groups=1 and base_width=64")
            self.conv = conv3x3(inchannel=inchannel,
                                outchannel=outchannel,
                                stride=stride)
            self.batch = op.BatchNorm2d(num_features=outchannel)
            self.relu = op.ReLU(inplace=True)
            self.conv2 = conv3x3(inchannel=outchannel, outchannel=outchannel)
            self.batch2 = op.BatchNorm2d(num_features=outchannel)
        else:
            self.conv = conv3x3(inchannel=inchannel,
                                outchannel=inner_plane,
                                stride=stride)
            self.batch = op.BatchNorm2d(num_features=inner_plane)
            self.relu = op.ReLU(inplace=True)
            self.conv2 = conv3x3(inchannel=inner_plane, outchannel=outchannel)
            self.batch2 = op.BatchNorm2d(num_features=outchannel)
Esempio n. 7
0
    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)
Esempio n. 8
0
    def __init__(self, inchannel, outchannel, groups, base_width, stride=1):
        """Create BottleneckBlock layers.

        :param inchannel: input channel.
        :type inchannel: int
        :param outchannel: output channel.
        :type outchannel: int
        :param stride: the number to jump, default 1
        :type stride: int
        """
        super(BottleneckBlock, self).__init__(inchannel, outchannel, groups,
                                              base_width, stride)
        bottle_conv = BottleConv(inchannel=inchannel,
                                 outchannel=outchannel,
                                 expansion=self.expansion,
                                 stride=stride,
                                 groups=groups,
                                 base_width=base_width)
        shortcut = ShortCut(inchannel=inchannel,
                            outchannel=outchannel,
                            expansion=self.expansion,
                            stride=stride)
        self.block = Add(bottle_conv, shortcut)
        self.relu = op.ReLU()