Example #1
0
    def __init__(self, in_planes, planes, stride=1):
        super(Bottleneck, self).__init__()
        self.conv1 = QWAConv2D(in_planes, planes, kernel_size=1, bias=True)
        self.conv2 = QWAConv2D(planes,
                               planes,
                               kernel_size=3,
                               stride=stride,
                               padding=1,
                               bias=True)
        self.conv3 = QWAConv2D(planes, planes * 4, kernel_size=1, bias=True)
        self.relu = nn.ReLU6(inplace=True)

        self.shortcut = nn.Sequential()
        if stride != 1 or in_planes != self.expansion * planes:
            self.downsample = True
            self.shortcut = nn.Sequential(
                QWAConv2D(in_planes,
                          self.expansion * planes,
                          kernel_size=1,
                          stride=stride,
                          bias=True))
        else:
            self.downsample = False

        self.stride = stride
Example #2
0
 def __init__(self, inplanes, planes, stride=1, downsample=None):
     super(Bottleneck, self).__init__()
     self.conv1 = QWAConv2D(inplanes, planes, kernel_size=1, bias=True)
     self.conv2 = QWAConv2D(planes, planes, kernel_size=3, stride=stride,
                           padding=1, bias=True)
     self.conv3 = QWAConv2D(planes, planes * 4, kernel_size=1, bias=True)
     self.relu = nn.ReLU(inplace=True)
     self.downsample = downsample
     self.stride = stride
Example #3
0
def conv3x3(in_planes, out_planes, stride=1):
    """3x3 convolution with padding"""
    return QWAConv2D(in_planes,
                     out_planes,
                     kernel_size=3,
                     stride=stride,
                     padding=1,
                     bias=False)
Example #4
0
def make_layers(cfg, batch_norm=False):
    layers = []
    in_channels = 3
    for v in cfg:
        if v == 'M':
            layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
        else:
            conv2d = QWAConv2D(in_channels, v, kernel_size=3, padding=1)
            if batch_norm:
                layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU6(inplace=True)]
            else:
                layers += [conv2d, nn.ReLU6(inplace=True)]
            in_channels = v
    return nn.Sequential(*layers)
Example #5
0
    def _make_layer(self, block, planes, blocks, stride=1):
        downsample = None
        if stride != 1 or self.inplanes != planes * block.expansion:
            downsample = nn.Sequential(
                QWAConv2D(self.inplanes, planes * block.expansion,
                         kernel_size=1, stride=stride, bias=True),
            )

        layers = []
        layers.append(block(self.inplanes, planes, stride, downsample))
        self.inplanes = planes * block.expansion
        for i in range(1, blocks):
            layers.append(block(self.inplanes, planes))

        return nn.Sequential(*layers)
Example #6
0
    def __init__(self, in_planes, planes, stride=1):
        super(BasicBlock, self).__init__()
        self.conv1 = conv3x3(in_planes, planes, stride)
        self.relu = nn.ReLU6(inplace=True)
        self.conv2 = conv3x3(planes, planes)
        self.shortcut = nn.Sequential()
        if stride != 1 or in_planes != self.expansion * planes:
            self.downsample = True
            self.shortcut = nn.Sequential(
                QWAConv2D(in_planes,
                          self.expansion * planes,
                          kernel_size=1,
                          stride=stride,
                          bias=True))
        else:
            self.downsample = False

        self.stride = stride