Beispiel #1
0
 def __init__(self, in_planes, planes, stride=1, option='A'):
     super(BasicBlock_1w1a, self).__init__()
     self.conv1 = ir_1w1a.IRConv2d(in_planes,
                                   planes,
                                   kernel_size=3,
                                   stride=stride,
                                   padding=1,
                                   bias=False)
     self.bn1 = nn.BatchNorm2d(planes)
     self.conv2 = ir_1w1a.IRConv2d(planes,
                                   planes,
                                   kernel_size=3,
                                   stride=1,
                                   padding=1,
                                   bias=False)
     self.bn2 = nn.BatchNorm2d(planes)
     self.shortcut = nn.Sequential()
     if stride != 1 or in_planes != planes:
         if option == 'A':
             """
             For CIFAR10 ResNet paper uses option A.
             """
             self.shortcut = LambdaLayer(lambda x: F.pad(
                 x[:, :, ::2, ::2],
                 (0, 0, 0, 0, planes // 4, planes // 4), "constant", 0))
         elif option == 'B':
             self.shortcut = nn.Sequential(
                 ir_1w1a.IRConv2d(in_planes,
                                  self.expansion * planes,
                                  kernel_size=1,
                                  stride=stride,
                                  bias=False),
                 nn.BatchNorm2d(self.expansion * planes))
Beispiel #2
0
    def __init__(self, num_classes=10):
        super(VGG_SMALL_bi_1W1A, self).__init__()

        self.ch_bi = change_to_bi()
        #self.conv0 = ir_1w1a.my_Conv2d(3, 128, kernel_size=(
        #    3, 24), padding=(1, 8), stride=(1, 8), bias=False)
        self.conv0 = ir_1w1a.my_Conv2d(3,
                                       128,
                                       kernel_size=(1, 8),
                                       stride=(1, 8),
                                       bias=False)

        # self.hold_to_bi = hold_to_bi(32, 32, inplanes=3, expansion=3)
        # self.conv0 = ir_1w1a.IRConv2d(
        #     9, 128, kernel_size=1, padding=0, bias=False)
        # self.conv0 = nn.Conv2d(3, 128, kernel_size=1, padding=0, bias=False)
        # self.conv0 = nn.Conv2d(3, 128, kernel_size=3, padding=1, bias=False)
        # self.conv0 = ir_1w1a.IRConv2d(
        #    3, 128, kernel_size = 1, padding = 1, bias = False)
        self.bn0 = nn.BatchNorm2d(128)

        self.conv1 = ir_1w1a.IRConv2d(128,
                                      128,
                                      kernel_size=3,
                                      padding=1,
                                      bias=False)
        self.pooling = nn.MaxPool2d(kernel_size=2, stride=2)
        self.bn1 = nn.BatchNorm2d(128)
        # self.nonlinear = nn.ReLU(inplace=True)
        self.nonlinear = nn.Hardtanh(inplace=True)
        self.conv2 = ir_1w1a.IRConv2d(128,
                                      256,
                                      kernel_size=3,
                                      padding=1,
                                      bias=False)
        self.bn2 = nn.BatchNorm2d(256)
        self.conv3 = ir_1w1a.IRConv2d(256,
                                      256,
                                      kernel_size=3,
                                      padding=1,
                                      bias=False)
        self.bn3 = nn.BatchNorm2d(256)
        self.conv4 = ir_1w1a.IRConv2d(256,
                                      512,
                                      kernel_size=3,
                                      padding=1,
                                      bias=False)
        self.bn4 = nn.BatchNorm2d(512)
        self.conv5 = ir_1w1a.IRConv2d(512,
                                      512,
                                      kernel_size=3,
                                      padding=1,
                                      bias=False)
        self.bn5 = nn.BatchNorm2d(512)
        self.fc = nn.Linear(512 * 4 * 4, num_classes)
        self._initialize_weights()
Beispiel #3
0
 def __init__(self, num_classes=10):
     super(VGG_SMALL_1W1A, self).__init__()
     self.conv0 = nn.Conv2d(3, 128, kernel_size=3, padding=1, bias=False)
     self.bn0 = nn.BatchNorm2d(128)
     self.conv1 = ir_1w1a.IRConv2d(128, 128, kernel_size=3, padding=1, bias=False)
     self.pooling = nn.MaxPool2d(kernel_size=2, stride=2)
     self.bn1 = nn.BatchNorm2d(128)
     # self.nonlinear = nn.ReLU(inplace=True)
     self.nonlinear = nn.Hardtanh(inplace=True)
     self.conv2 = ir_1w1a.IRConv2d(128, 256, kernel_size=3, padding=1, bias=False)
     self.bn2 = nn.BatchNorm2d(256)
     self.conv3 = ir_1w1a.IRConv2d(256, 256, kernel_size=3, padding=1, bias=False)
     self.bn3 = nn.BatchNorm2d(256)
     self.conv4 = ir_1w1a.IRConv2d(256, 512, kernel_size=3, padding=1, bias=False)
     self.bn4 = nn.BatchNorm2d(512)
     self.conv5 = ir_1w1a.IRConv2d(512, 512, kernel_size=3, padding=1, bias=False)
     self.bn5 = nn.BatchNorm2d(512)
     self.fc = nn.Linear(512*4*4, num_classes)
     self._initialize_weights()