Example #1
0
    def __init__(self, in_planes, planes, dropout_rate, fix_points, stride=1):
        super(WideBasicCurve, self).__init__()
        self.bn1 = curves.BatchNorm2d(in_planes, fix_points=fix_points)
        self.conv1 = curves.Conv2d(in_planes,
                                   planes,
                                   kernel_size=3,
                                   padding=1,
                                   bias=True,
                                   fix_points=fix_points)
        self.dropout = nn.Dropout(p=dropout_rate)
        self.bn2 = curves.BatchNorm2d(planes, fix_points=fix_points)
        self.conv2 = curves.Conv2d(planes,
                                   planes,
                                   kernel_size=3,
                                   stride=stride,
                                   padding=1,
                                   bias=True,
                                   fix_points=fix_points)

        self.shortcut = None
        if stride != 1 or in_planes != planes:
            self.shortcut = curves.Conv2d(in_planes,
                                          planes,
                                          kernel_size=1,
                                          stride=stride,
                                          bias=True,
                                          fix_points=fix_points)
Example #2
0
 def __init__(self,
              inplanes,
              planes,
              fix_points,
              stride=1,
              downsample=None):
     super(BottleneckCurve, self).__init__()
     self.bn1 = curves.BatchNorm2d(inplanes, fix_points=fix_points)
     self.conv1 = curves.Conv2d(inplanes,
                                planes,
                                kernel_size=1,
                                bias=False,
                                fix_points=fix_points)
     self.bn2 = curves.BatchNorm2d(planes, fix_points=fix_points)
     self.conv2 = curves.Conv2d(planes,
                                planes,
                                kernel_size=3,
                                stride=stride,
                                padding=1,
                                bias=False,
                                fix_points=fix_points)
     self.bn3 = curves.BatchNorm2d(planes, fix_points=fix_points)
     self.conv3 = curves.Conv2d(planes,
                                planes * 4,
                                kernel_size=1,
                                bias=False,
                                fix_points=fix_points)
     self.relu = nn.ReLU(inplace=True)
     self.downsample = downsample
     self.stride = stride
Example #3
0
 def __init__(self, inplanes, planes, fix_points, stride=1, downsample=None):
     super(BasicBlockCurve, self).__init__()
     self.bn1 = curves.BatchNorm2d(inplanes, fix_points=fix_points)
     self.relu = nn.ReLU(inplace=True)
     self.conv1 = conv3x3curve(inplanes, planes, stride=stride, fix_points=fix_points)
     self.bn2 = curves.BatchNorm2d(planes, fix_points=fix_points)
     self.conv2 = conv3x3curve(planes, planes, fix_points=fix_points)
     self.downsample = downsample
     self.stride = stride
 def __init__(self, in_planes, growth_rate, fix_points):
     super(Bottleneck, self).__init__()
     self.bn1 = curves.BatchNorm2d(in_planes, fix_points=fix_points)
     self.conv1 = curves.Conv2d(in_planes,
                                4 * growth_rate,
                                kernel_size=1,
                                bias=False,
                                fix_points=fix_points)
     self.bn2 = curves.BatchNorm2d(4 * growth_rate, fix_points=fix_points)
     self.conv2 = curves.Conv2d(4 * growth_rate,
                                growth_rate,
                                kernel_size=3,
                                padding=1,
                                bias=False,
                                fix_points=fix_points)
Example #5
0
    def __init__(self, num_classes, fix_points, depth=110):
        super(PreResNetCurve, self).__init__()
        if depth >= 44:
            assert (depth - 2) % 9 == 0, 'depth should be 9n+2'
            n = (depth - 2) // 9
            block = BottleneckCurve
        else:
            assert (depth - 2) % 6 == 0, 'depth should be 6n+2'
            n = (depth - 2) // 6
            block = BasicBlockCurve

        self.inplanes = 16
        self.conv1 = curves.Conv2d(3, 16, kernel_size=3, padding=1,
                                   bias=False, fix_points=fix_points)
        self.layer1 = self._make_layer(block, 16, n, fix_points=fix_points)
        self.layer2 = self._make_layer(block, 32, n, stride=2, fix_points=fix_points)
        self.layer3 = self._make_layer(block, 64, n, stride=2, fix_points=fix_points)
        self.bn = curves.BatchNorm2d(64 * block.expansion, fix_points=fix_points)
        self.relu = nn.ReLU(inplace=True)
        self.avgpool = nn.AvgPool2d(8)
        self.fc = curves.Linear(64 * block.expansion, num_classes, fix_points=fix_points)

        for m in self.modules():
            if isinstance(m, curves.Conv2d):
                n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
                for i in range(m.num_bends):
                    getattr(m, 'weight_%d' % i).data.normal_(0, math.sqrt(2. / n))
            elif isinstance(m, curves.BatchNorm2d):
                for i in range(m.num_bends):
                    getattr(m, 'weight_%d' % i).data.fill_(1)
                    getattr(m, 'bias_%d' % i).data.zero_()
    def __init__(self, num_classes, fix_points, depth=28, k=10, p=0):
        super(WideResNetCurve, self).__init__()
        self.in_planes = 16

        assert ((depth - 4) % 6 == 0), 'Wide-resnet depth should be 6n+4'
        n = (depth - 4) / 6

        nstages = [16, 16 * k, 32 * k, 64 * k]

        self.conv1 = conv3x3curve(3, nstages[0], fix_points=fix_points)
        self.layer1 = self._wide_layer(WideBasicCurve,
                                       nstages[1],
                                       n,
                                       p,
                                       stride=1,
                                       fix_points=fix_points)
        self.layer2 = self._wide_layer(WideBasicCurve,
                                       nstages[2],
                                       n,
                                       p,
                                       stride=2,
                                       fix_points=fix_points)
        self.layer3 = self._wide_layer(WideBasicCurve,
                                       nstages[3],
                                       n,
                                       p,
                                       stride=2,
                                       fix_points=fix_points)
        self.bn1 = curves.BatchNorm2d(nstages[3],
                                      momentum=0.9,
                                      fix_points=fix_points)
        self.linear = curves.Linear(nstages[3],
                                    num_classes,
                                    fix_points=fix_points)
 def __init__(self, in_planes, out_planes, fix_points):
     super(Transition, self).__init__()
     self.bn = curves.BatchNorm2d(in_planes, fix_points=fix_points)
     self.conv = curves.Conv2d(in_planes,
                               out_planes,
                               kernel_size=1,
                               bias=False,
                               fix_points=fix_points)
    def __init__(self,
                 num_classes,
                 fix_points,
                 block=BottleneckCurve,
                 nblocks=[6, 12, 24, 16],
                 growth_rate=12,
                 reduction=0.5):
        super(DenseNetCurve, self).__init__()
        self.growth_rate = growth_rate

        num_planes = 2 * growth_rate
        self.conv1 = curves.Conv2d(3,
                                   num_planes,
                                   kernel_size=3,
                                   padding=1,
                                   bias=False,
                                   fix_points=fix_points)

        self.dense1 = self._make_dense_layers(block,
                                              num_planes,
                                              nblocks[0],
                                              fix_points=fix_points)
        num_planes += nblocks[0] * growth_rate
        out_planes = int(math.floor(num_planes * reduction))
        self.trans1 = Transition(num_planes, out_planes, fix_points)
        num_planes = out_planes

        self.dense2 = self._make_dense_layers(block,
                                              num_planes,
                                              nblocks[1],
                                              fix_points=fix_points)
        num_planes += nblocks[1] * growth_rate
        out_planes = int(math.floor(num_planes * reduction))
        self.trans2 = Transition(num_planes, out_planes, fix_points)
        num_planes = out_planes

        self.dense3 = self._make_dense_layers(block,
                                              num_planes,
                                              nblocks[2],
                                              fix_points=fix_points)
        num_planes += nblocks[2] * growth_rate
        out_planes = int(math.floor(num_planes * reduction))
        self.trans3 = Transition(num_planes, out_planes, fix_points)
        num_planes = out_planes

        self.dense4 = self._make_dense_layers(block,
                                              num_planes,
                                              nblocks[3],
                                              fix_points=fix_points)
        num_planes += nblocks[3] * growth_rate

        self.bn = curves.BatchNorm2d(num_planes, fix_points=fix_points)
        self.linear = curves.Linear(num_planes,
                                    num_classes,
                                    fix_points=fix_points)