Esempio n. 1
0
    def __init__(self, noise='bernoulli', xavier_init=False):
        super(MNIST, self).__init__()
        input_shape = (28, 28)
        self.conv1 = NSMConv2d_(1,
                                32,
                                kernel_size=(5, 5),
                                prob=0.25,
                                bias=True,
                                input_shape=input_shape,
                                noise=noise)
        input_shape = (12, 12)
        self.conv2 = NSMConv2d_(32,
                                64,
                                kernel_size=(5, 5),
                                prob=0.25,
                                bias=True,
                                noise=noise,
                                input_shape=input_shape)
        self.max_pool = nn.MaxPool2d(kernel_size=2)
        self.fc1 = NSMLinear_(64 * 4 * 4,
                              512,
                              prob=0.5,
                              bias=True,
                              noise=noise)
        self.fc2 = nn.Linear(512, 10)
        self.dropout = nn.Dropout(p=0.5)
        self.sign = Sign_().apply
        self.tanh = nn.Tanh()

        if xavier_init is True:
            for name in self.named_parameters():
                if 'weight' in name[0]:
                    nn.init.xavier_uniform_(name[1].data)
Esempio n. 2
0
    def __init__(self):
        super(allconvnet64, self).__init__()
        self.sign = Sign_().apply
        self.mpool = nn.MaxPool2d(kernel_size=2, stride=2)
        self.dropout = nn.Dropout(.5)
        self.apool = nn.AvgPool2d(kernel_size=8)
        self.relu = nn.LeakyReLU(negative_slope=0.1)
        self.tanh = nn.Tanh()

        self.noise = GaussianNoise(sigma=0.15)
        self.b1 = nn.BatchNorm2d(N1)

        self.input = weight_norm(nn.Conv2d(3,
                                           N1,
                                           kernel_size=(3, 3),
                                           padding=(1, 1)),
                                 name='weight',
                                 dim=None)
        self.convset1 = nn.ModuleList([
            weight_norm(nn.Conv2d(N1, N1, kernel_size=(3, 3), padding=[1, 1]),
                        name='weight',
                        dim=None),
            weight_norm(nn.Conv2d(N1, N1, kernel_size=(3, 3), padding=[1, 1]),
                        name='weight',
                        dim=None),
            weight_norm(nn.Conv2d(N1, N1, kernel_size=(3, 3), padding=[1, 1]),
                        name='weight',
                        dim=None)
        ])
        self.convset2 = nn.ModuleList([
            weight_norm(nn.Conv2d(N1, N2, kernel_size=(3, 3), padding=[1, 1]),
                        name='weight',
                        dim=None),
            weight_norm(nn.Conv2d(N2, N2, kernel_size=(3, 3), padding=[1, 1]),
                        name='weight',
                        dim=None),
            weight_norm(nn.Conv2d(N2, N2, kernel_size=(3, 3), padding=[1, 1]),
                        name='weight',
                        dim=None)
        ])
        self.convset3 = nn.ModuleList([
            weight_norm(nn.Conv2d(N2, N3, kernel_size=(3, 3), padding=[0, 0]),
                        name='weight',
                        dim=None)
        ])
        self.nin1 = weight_norm(nn.Conv2d(N3,
                                          N3,
                                          kernel_size=(1, 1),
                                          padding=[0, 0]),
                                name='weight',
                                dim=None)
        self.nin2 = weight_norm(nn.Conv2d(N3,
                                          N3,
                                          kernel_size=(1, 1),
                                          padding=[0, 0]),
                                name='weight',
                                dim=None)
        self.fc_out = weight_norm(nn.Linear(in_features=N3, out_features=10),
                                  name='weight',
                                  dim=None)
Esempio n. 3
0
 def __init__(self, noise='bernoulli', batch_size=32):
     super(NMNIST_MODEL, self).__init__()
     # self.fc_in = Lambda_(lambda x: self.sign(2 * x - 1))
     # self.fc_in = nn.Conv2d(1, 1, 1, bias=True)
     input_shape = (34, 34)
     self.fc_in = nn.Conv2d(1, 1, kernel_size=(1, 1))
     self.conv1 = NSMConv2d_(10,
                             32,
                             kernel_size=(5, 5),
                             prob=0.25,
                             bias=True,
                             noise=noise,
                             input_shape=input_shape)
     input_shape = (15, 15)
     self.conv2 = NSMConv2d_(32,
                             64,
                             kernel_size=(5, 5),
                             prob=0.25,
                             bias=True,
                             noise=noise,
                             input_shape=input_shape)
     self.max_pool = nn.MaxPool2d(kernel_size=2)
     self.fc1 = NSMLinear_(64 * 5 * 5, 150, prob=0.5, bias=True)
     self.fc2 = nn.Linear(150, 10)
     self.dropout = nn.Dropout(p=0.5)
     self.sign = Sign_().apply
     self.tanh = nn.Tanh()
Esempio n. 4
0
 def __init__(self, noise='bernoulli', batch_size=32):
     super(eMNIST, self).__init__()
     input_shape = (28, 28)
     self.fc_in = nn.Conv2d(1, 1, kernel_size=(1, 1))
     self.conv1 = NSMConv2d_(1,
                             32,
                             kernel_size=(5, 5),
                             prob=0.25,
                             bias=True,
                             noise=noise,
                             input_shape=input_shape)
     input_shape = (12, 12)
     self.conv2 = NSMConv2d_(32,
                             64,
                             kernel_size=(5, 5),
                             prob=0.25,
                             bias=True,
                             noise=noise,
                             input_shape=input_shape)
     self.max_pool = nn.MaxPool2d(kernel_size=2)
     self.fc1 = NSMLinear_(64 * 4 * 4, 150, prob=0.5, bias=True)
     self.fc2 = nn.Linear(150, 26)
     self.dropout = nn.Dropout(p=0.5)
     self.sign = Sign_().apply
     self.tanh = nn.Tanh()
 def __init__(self):
     super(allconvnet64, self).__init__()
     self.sign = Sign_().apply
     self.mpool = nn.MaxPool2d(kernel_size=2)
     self.apool = nn.AvgPool2d(kernel_size=8)
     self.relu = nn.ReLU()
     # self.relu = nn.LeakyReLU(negative_slope=0.1)
     self.convset1 = nn.ModuleList([
         weight_norm(nn.Conv2d(6, N1, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N1),
         weight_norm(nn.Conv2d(N1, N1, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N1),
         weight_norm(nn.Conv2d(N1, N1, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N1),
         nn.MaxPool2d(kernel_size=2),
         nn.Dropout(.5)
     ])
     self.convset2 = nn.ModuleList([
         weight_norm(nn.Conv2d(N1, N2, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N2),
         weight_norm(nn.Conv2d(N2, N2, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N2),
         weight_norm(nn.Conv2d(N2, N2, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N2),
         nn.MaxPool2d(kernel_size=2),
         nn.Dropout(.5)
     ])
     self.convset3 = nn.ModuleList([
         weight_norm(nn.Conv2d(N2, N3, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N3),
         weight_norm(nn.Conv2d(N3, N3, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N3),
         weight_norm(nn.Conv2d(N3, N3, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N3),
         nn.MaxPool2d(kernel_size=2),
         nn.Dropout(.5)
     ])
     self.convset4 = nn.ModuleList([
         weight_norm(nn.Conv2d(N3, N4, kernel_size=(3, 3), padding=[1, 1]),
                     name='weight'),
         # nn.BatchNorm2d(N4),
         weight_norm(nn.Conv2d(N4, N4, kernel_size=(1, 1), padding=[0, 0]),
                     name='weight'),
         # nn.BatchNorm2d(N4),
         weight_norm(nn.Conv2d(N4, N4, kernel_size=(1, 1), padding=[0, 0]),
                     name='weight')
     ])
     self.fc_out = nn.Linear(in_features=N4, out_features=11)
     # self.bn_in = nn.BatchNorm2d(6)
     self.bn = nn.BatchNorm2d(256)
 def __init__(self, batch_size=32, device=0):
     super(cMNIST, self).__init__()
     self.conv1 = nn.Conv2d(1, 32, kernel_size=(5, 5))
     self.conv2 = nn.Conv2d(32, 64, kernel_size=(5, 5))
     self.max_pool = nn.MaxPool2d(kernel_size=2)
     self.fc1 = nn.Linear(64 * 4 * 4, 150)
     self.fc2 = nn.Linear(150, 10)
     self.relu = nn.ReLU()
     self.dropout = nn.Dropout(p=0.5)
     self.softmax = nn.Softmax(dim=1)
     self.sign = Sign_().apply
    def __init__(self, noise='bernoulli', xavier_init=False):
        super(mnist_, self).__init__()
        self.fc1 = NSMLinear_(784, 300, prob=0.5, bias=True, noise=noise)
        self.fc2 = NSMLinear_(300, 300, prob=0.5, bias=True, noise=noise)
        self.fc3 = NSMLinear_(300, 300, prob=0.5, bias=True, noise=noise)
        self.fc4 = nn.Linear(300, 10)
        self.sign = Sign_().apply
        self.tanh = nn.Tanh()

        if xavier_init is True:
            for name in self.named_parameters():
                if 'weight' in name[0]:
                    nn.init.xavier_uniform_(name[1].data)
Esempio n. 8
0
    def __init__(self, xavier_init=False):
        super(mnist_, self).__init__()
        self.fc1 = nn.Linear(784, 300)
        self.fc2 = nn.Linear(300, 300)
        self.fc3 = nn.Linear(300, 300)
        self.fc4 = nn.Linear(300, 10)
        self.sign = Sign_().apply
        self.relu = nn.ReLU()
        self.dropout = nn.Dropout(.5)

        if xavier_init is True:
            for name in self.named_parameters():
                if 'weight' in name[0]:
                    nn.init.xavier_uniform_(name[1].data)
    def __init__(self, noise='bernoulli'):
        super(allnsmconvnet64, self).__init__()
        self.sign = Sign_().apply
        self.mpool = nn.MaxPool2d(kernel_size=2, stride=2)
        self.apool = nn.AvgPool2d(kernel_size=8)

        self.noise = GaussianNoise(sigma=0.15)
        self.input = nn.Conv2d(3, N1, kernel_size=(3, 3), padding=(1, 1))
        self.b0 = nn.BatchNorm2d(3)
        self.b1 = nn.BatchNorm2d(N1)
        self.b2 = nn.BatchNorm1d(N3)

        self.convset1 = nn.ModuleList([
            NSMConv2d_(N1,
                       N1,
                       kernel_size=(3, 3),
                       prob=.5,
                       padding=[1, 1],
                       input_shape=[32, 32],
                       noise=noise,
                       bias=False),
            NSMConv2d_(N1,
                       N1,
                       kernel_size=(3, 3),
                       prob=.5,
                       padding=[1, 1],
                       input_shape=[32, 32],
                       noise=noise,
                       bias=False),
            NSMConv2d_(N1,
                       N1,
                       kernel_size=(3, 3),
                       prob=.5,
                       padding=[1, 1],
                       input_shape=[32, 32],
                       noise=noise,
                       bias=False)
        ])
        self.convset2 = nn.ModuleList([
            NSMConv2d_(N1,
                       N2,
                       kernel_size=(3, 3),
                       prob=.5,
                       padding=[1, 1],
                       input_shape=[16, 16],
                       noise=noise,
                       bias=False),
            NSMConv2d_(N2,
                       N2,
                       kernel_size=(3, 3),
                       prob=.5,
                       padding=[1, 1],
                       input_shape=[16, 16],
                       noise=noise,
                       bias=False),
            NSMConv2d_(N2,
                       N2,
                       kernel_size=(3, 3),
                       prob=.5,
                       padding=[1, 1],
                       input_shape=[16, 16],
                       noise=noise,
                       bias=False)
        ])
        self.convset3 = nn.ModuleList([
            NSMConv2d_(N2,
                       N3,
                       kernel_size=(3, 3),
                       prob=.5,
                       padding=[1, 1],
                       input_shape=[8, 8],
                       noise=noise,
                       bias=False),
            NSMConv2d_(N3,
                       N3,
                       kernel_size=(1, 1),
                       prob=.5,
                       padding=[0, 0],
                       input_shape=[8, 8],
                       noise=noise,
                       bias=False),
            NSMConv2d_(N3,
                       N3,
                       kernel_size=(1, 1),
                       prob=.5,
                       padding=[0, 0],
                       input_shape=[8, 8],
                       noise=noise,
                       bias=False)
        ])
        self.fc_out = nn.Linear(in_features=N3, out_features=100)
        self.tanh = nn.Tanh()
 def __init__(self, noise='bernoulli'):
     super(allnsmconvnet64, self).__init__()
     self.sign = Sign_().apply
     self.mpool = nn.MaxPool2d(kernel_size=2)
     self.apool = nn.AvgPool2d(kernel_size=8)
     self.convset1 = nn.ModuleList([
         NSMConv2d_(6,
                    N1,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[64, 64],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N1,
                    N1,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[64, 64],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N1,
                    N1,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[64, 64],
                    noise=noise,
                    bias=True)
     ])
     self.convset2 = nn.ModuleList([
         NSMConv2d_(N1,
                    N2,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[32, 32],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N2,
                    N2,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[32, 32],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N2,
                    N2,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[32, 32],
                    noise=noise,
                    bias=True)
     ])
     self.convset3 = nn.ModuleList([
         NSMConv2d_(N2,
                    N3,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[16, 16],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N3,
                    N3,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[16, 16],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N3,
                    N3,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[16, 16],
                    noise=noise,
                    bias=True)
     ])
     self.convset4 = nn.ModuleList([
         NSMConv2d_(N3,
                    N4,
                    kernel_size=(3, 3),
                    prob=.5,
                    padding=[1, 1],
                    input_shape=[8, 8],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N4,
                    N4,
                    kernel_size=(1, 1),
                    prob=.5,
                    padding=[0, 0],
                    input_shape=[8, 8],
                    noise=noise,
                    bias=True),
         NSMConv2d_(N4,
                    N4,
                    kernel_size=(1, 1),
                    prob=.5,
                    padding=[0, 0],
                    input_shape=[8, 8],
                    noise=noise,
                    bias=True)
     ])
     self.fc_out = nn.Linear(in_features=N4, out_features=11)