Пример #1
0
    def __init__(self,
                 inplanes,
                 planes,
                 kernel_size=3,
                 stride=1,
                 downsample=None):
        super(BasicBlock, self).__init__()
        self.conv1 = nn.conv2d(inplanes,
                               planes,
                               kernel_size,
                               stride,
                               padding=1,
                               bias=False)
        self.bn1 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)
        self.relu = nn.ReLU(inplace=True)

        self.conv2 = nn.conv2d(planes,
                               planes,
                               kernel_size,
                               stride,
                               padding=1,
                               bias=False)
        self.bn2 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)
        self.downsample = downsample
        self.stride = stride
Пример #2
0
 def conv_3_block(in_dim, out_dim):  # 3개의 합성곱 레이어를 만드는 콘브 블럭입니다.
     model = nn.Sequential(
         nn.Conv2d(in_dim, out_dim, kernel_size=3, padding=1), nn.ReLU(),
         nn.conv2d(out_dim, out_dim, kernel_size=3, padding=1), nn.ReLU(),
         nn.conv2d(out_dim, out_dim, kernel_size=3, padding=1), nn.ReLU(),
         nn.MaxPool2d(2, 2))
     return model
Пример #3
0
 def __init__(self):
     super(Net, self).__init__()
     self.conv1 = nn.conv2d(3, 6, 5)
     self.pool = nn.MaxPool2d(2, 2)
     self.conv2 = nn.conv2d(6, 16, 5)
     self.fc1 = nn.Linear(16 * 18 * 18, 800)
     self.fc2 = nn.Linear(800, 120)
     self.fc3 = nn.Linear(120, 2)
Пример #4
0
 def __init__(self):
     super().__init__()
     self.conv1  = nn.conv2d(1, 6, kernel_size = 5)
     self.conv2  = nn.conv2d(6, 16, kernel_size = 5)
     self.pool1  = nn.MaxPool2d((2, 2), stride = 2) 
     self.pool2  = nn.MaxPool2d((2, 2), stride = 2) 
     self.linear1 = nn.Linear(16 * 5 * 5, 120)
     self.linear2 = nn.Linear(120, 84)
     self.linear3 = nn.Linear(84, 10)
     self.relu    = nn.ReLU(inplace = True)
Пример #5
0
    def __init__(self,inplanes,planes,stride=1,downsample=None):
        #construct a sample, build layers, 3x3 convolutional layers
        super(BasicBlock,self).__init__()
        self.conv1 = nn.conv2d(inplanes,planes,stride)
        self.bn1 = nn.BatchNorm2d(planes)
        self.relu = nn.ReLU(inplace=True)

        self.conv2 = nn.conv2d(planes,planes,stride)
        self.bn2 = nn.BatchNorm2d(planes)
        self.downsample = downsample
        self.stride=stride
Пример #6
0
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.conv2d(1, 32, 5, 2, padding=2)
        self.conv2 = nn.conv2d(16, 64, 5, 2, padding=2)
        self.conv3 = nn.conv2d(64, 32, 5, 2, padding=2)

        self.fc1 = nn.Linear(512, 64)
        self.fc2 = nn.Linear(64, 32)
        self.fc3 = nn.Linear(32, 8)
        self.fc4 = nn.Linear(8, 1)

        self.init_weights()
    def __init__(self):
        super(SensorToDryspotBoolModel, self).__init__()
        self.dropout = nn.dropout(0.1)
        self.maxpool = nn.maxpool2d(2, 2)
        self.conv1 = nn.conv2d(1, 32, (7, 7))
        self.conv2 = nn.conv2d(32, 64, (5, 5))
        self.conv3 = nn.conv2d(64, 128, (3, 3))
        self.conv4 = nn.conv2d(128, 256, (3, 3))

        self.fc1 = nn.linear(256, 1024)
        self.fc2 = nn.linear(1024, 512)
        self.fc3 = nn.linear(512, 128)
        self.fc_f = nn.linear(128, 1)
Пример #8
0
 def __init__(self, args):
     super(Net, self).__init__()
     self.conv1 = nn.Conv2d(1, 4, 5)
     self.pool = nn.MaxPool2d(2, 2)
     self.conv2 = nn.conv2d(4, 4, 5)
     self.fc1 = nn.Linear(4 * 37 * 37, 256)
     self.fc2 = nn.Linear(256, 15)
Пример #9
0
 def __init__(self):
     super(Net, self).__init__()
     self.conv1 = nn.Conv2d(1, 6, 3)
     self.conv2 = nn.conv2d(6, 16, 3)
     self.fc1 = nn.linear(16 * 6 * 6, 120)
     self.fc2 - nn.Linear(120, 84)
     self.fc3 = nn.Linear(84, 10)
Пример #10
0
    def forward(self, input, generation_input):
        size = input.size()
        batch_size = size[0]
        channels = size[1]

        weights = self.generator(generation_input)
        weight_size = weights.size()
        weights.reshape(batch_size * weight_size[0], weight_size[1],
                        weight_size[2], weight_size[3])
        weight_size = weights.size()

        # weight size resolution:
        assert (weight_size[0] % batch_size == 0,
                "Filter size not an integer multiple of the batch size!")
        out_channels = weight_size[0] // batch_size
        filters = weight_size[1]
        width = weight_size[2]
        height = weight_size[3]

        filters = weight_size[1]
        debatched = input.reshape(channels * batch_size, size[2], size[3])
        result = nn.conv2d(debatched,
                           weights,
                           stride=self.stride,
                           padding=self.padding,
                           dilation=self.dilation,
                           groups=batch_size)
        result = result.reshape(batch_size, filters,
                                result.size()[2],
                                result.size()[3])
        return result
    def __init__(self, z_dim):
        super(Enocder, self).__init__()

        self.Activation = nn.LeakyReLU(inplace=True, negative_slope=0.2)

        self.normalization = nn.BatchNorm2d()

        self.conv1 = nn.Conv2d(in_channels=3,
                               out_channels=64,
                               kernel_size=4,
                               stride=2,
                               bias=True)  #32x32 --> 14x14

        self.conv2 = nn.Conv2d(in_channels=64,
                               out_channels=128,
                               kernel_size=4,
                               stride=2,
                               padding=1,
                               bias=True)  #14x14 --> 7x7

        self.conv3 = nn.conv2d(in_channels=128,
                               out_channels=256,
                               kernel_size=3,
                               stride=2,
                               padding=1,
                               bias=True)  #7x7 --> 4x4

        self.dense_net = nn.Linear(256 * 4 * 4, z_dim)
Пример #12
0
    def __init__(self, num_class=1000):
        super(AlexNet, self).__init__()
        self.features = nn.Swquential(
            nn.conv2d(3, 64, kernel_size=11, stride=4, padding=2),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2),
            nn.Conv2d(64, 192, kernel_size=3, stride=2),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2),
            nn.Conv2d(192, 384, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(384, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(256, 256, kernel_size=3, padding=1),
            nn.ReLU(inpalce=True),
            nn.MaxPool2d(kernel_size=3, stride=2),
        )
        self.classifier = nn.Sequential(
            nn.Dropout(),
            nn.Linear(256 * 6 * 6, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU(inplace=True),
            nn.Linear(4096, num_classes),
        )

        def forward(self, x):
            x = self.features(x)
            x = x.view(x.size(0), 256 * 6 * 6)
            x = self.classifier(x)
            return x
def conv3x3(in_channels, out_channels, stride=1):
    return nn.conv2d(in_channels,
                     out_channels,
                     kernet_size=3,
                     stride=stride,
                     padding=1,
                     bias=False)
Пример #14
0
 def __init__(self,
              input_shape=((4, 32, 32), (6, 16, 16)),
              feature_size=128,
              kernel_size=3):
     super(Net, self).__init__()
     self.conv1 = nn.Conv2d(1, feature_size, kernel_size, 1)
     self.conv2 = nn.conv2d(feature_size, input_shape[-1][0], kernel_size,
                            1)
     self.rBlock = ResBlock(feature_size, kernel_size)
Пример #15
0
 def __init__(self, input_size, output_size) -> None:
     """"""
     super(CNN, self).__init__()
     self.kernel_size = 3
     self.stride = 2
     self.layers = nn.Sequential(
         nn.conv2d(input_size, output_size, self.kernel_size, self.stride),
         nn.ReLU(),
         nn.MaxPool2d(),
     )
Пример #16
0
def build_dc_classifier():
    """
    Build and return a PyTorch model for the DCGAN discriminator implementing
    the architecture above.
    """
    model = nn.Sequential(
        Unflatten(batch_size,1,28,28),
        nn.conv2d(1,32,5,1),#32*24*24
        nn.LeakyReLU(inplace=True,negative_slope = 0.01),
        nn.MaxPool2d(2,2), #32*12*12
        nn.conv2d(32,64,5,1),# 64*8*8
        nn.LeakyReLU(inplace=True,negative_slope = 0.01),
        nn.MaxPool2d(2,2),#64*4*4
        Flatten(),
        nn.Linear(4*4*64,4*4*64)
        nn.LeakyReLU(inplace=True,negative_slope = 0.01),
        nn.Linear(4*4*64,1),
        )
    return model
Пример #17
0
    def __init__(self):
        super(vgg19ca, self).__init__()

        ############# 256-256  ##############
        #haze_class = models.vgg19_bn(pretrained=True)
        #self.feature = nn.Sequential(haze_class.features[0])

        #for i in range(1,3):
        #    self.feature.add_module(str(i),haze_class.features[i])
		self.conv1 = nn.conv2d(1,24,kernel_size=3,stride=1,padding=1)
		self.conv61 = nn.Conv2d(24,64,kernel_size=3,stride=1,padding=1)
Пример #18
0
 def __init__(self, in_channels, distillation_rate=0.25):
     super(IMDModule_speed, self).__init__()
     self.distilled_channels = int(in_channels * distillation_rate)
     self.remaining_channels = int(in_channels - self.distilled_channels)
     self.c1 = sequential(
         nn.conv2d(in_channels,
                   in_channels,
                   kernel_size=(1, 3),
                   dilation=(1, 2)),
         nn.conv2d(in_channels,
                   in_channels,
                   kernel_size=(3, 1),
                   dilation=(2, 1)),
     )
     self.c2 = conv_layer(self.remaining_channels, in_channels, 3)
     self.c3 = conv_layer(self.remaining_channels, in_channels, 3)
     self.c4 = conv_layer(self.remaining_channels, self.distilled_channels,
                          3)
     self.act = activation('lrelu', neg_slope=0.05)
     self.c5 = conv_layer(self.distilled_channels * 4, in_channels, 1)
    def build_classifier(input_features, hidden_layers, output_features):
        classifier = nn.conv2d()
        if hidden_layers is None:
            classifier.add_module('fc0',
                                  nn.conv2d(input_features, output_features))
        else:
            layer_sizes = zip(hidden_layers[:-1], hidden_layers[1:])
            classifier.add_module('fc0',
                                  nn.conv2d(input_features, hidden_layers[0]))
            classifier.add_module('relu0', nn.ReLU())
            classifier.add_module('drop0', nn.Dropout(.6))
            classifier.add_module('relu1', nn.ReLU())
            classifier.add_module('drop1', nn.Dropout(.5))
            for i, (h1, h2) in enumerate(layer_sizes):
                classifier.add_module('fc' + str(i + 1), nn.Linear(h1, h2))
                classifier.add_module('relu' + str(i + 1), nn.ReLU())
                classifier.add_module('drop' + str(i + 1), nn.Dropout(.5))
            classifier.add_module(
                'output', nn.Linear(hidden_layers[-1], output_features))

        return classifier
    def forward(self, x1, x2):
        x_mul = x1.mul(x2)
        x_add = torch.add(x1, x2)
        x_norm_l1 = torch.abs(x1 - x2)
        x_norm_l2 = x_norm_l1.mul(x_norm_l1)

        x = torch.cat((x_mul, x_add, x_norm_l1, x_norm_l2), 1)

        x = x.view(x1.size(0), 1, 4, x1.size(1))  # batch_size, c, h, w
        x = nn.Conv2d(1, 32, (1, 4))(x)
        x = x.view(x1.size(0), x1.size(1), 32, 1)
        x = nn.conv2d(512, 1, (1, 32))(x)

        x = x.view(x1.size(0), -1)

        return x
Пример #21
0
 def __init__(self, activation: str, mask_conv: bool):
     super(VGGExtractor, self).__init__(activation)
     self.mask_conv = mask_conv
     self.conv = nn.Sequential(
         nn.Conv2d(1, 64, kernel_size=3, stride=1, padding=1, bias=False),
         nn.BatchNorm2d(num_features=64), self.activation,
         nn.conv2d(64, 64, kernel_size=3, stride=1, padding=1, bias=False),
         nn.BatchNorm2d(num_feature=64), self.activation,
         nn.MaxPool2d(2, stride=2),
         nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1, bias=False),
         nn.BatchNorm2d(num_features=128), self.activation,
         nn.Conv2d(128, 128, kernel_size=3, strid=1, padding=1, bias=False),
         nn.BatchNorm2d(num_feature=128), self.activation,
         nn.MaxPool2d(2, stride=2))
     if mask_conv:
         self.conv = MaskConv(self.conv)
Пример #22
0
    def __init__(self, input_nc, ndf=64, norm_layer=nn.BatchNorm2d, use_sigmoid=False, gpu_ids=[]):
        super(ImgLSTM, self).__init__()
        
        #Setting
        self.gpu_ids = gpu_ids

        if type(norm_layer) == functools.partial:
            use_bias = norm_layer.func == nn.InstanceNorm2d
        else:
            use_bias = norm_layer == nn.InstanceNorm2d

        #Network
        self.net = [
            nn.Conv2d(input_nc,64, kernel_size=3, stride=1, bias=use_bias),
            nn.ReLu(True),
            nn.MaxPool2d(kernel_size=2,stride=2),

            nn.Conv2d(64,128, kernel_size=3, stride=1, bias=use_bias),
            nn.ReLu(True),
            nn.MaxPool2d(kernel_size=2,stride=2),

            nn.Conv2d(128,256,kernel_size=3,stride=1,bias=use_bias),
            nn.ReLu(True),

            nn.Conv2d(256,256,kernel_size=3,stride=1,bias=use_bias),
            nn.ReLu(True),
            nn.MaxPool2d(kernel_size=2,stride=1,bias=use_bias),

            nn.Conv2d(256,512,kernel_size=3,stride=1,bias=use_bias),
            nn.ReLu(True),

            nn.conv2d(512,512,kernel_size=3,stride=1,bias=use_bias),
            nn.ReLu(True),

            nn.MaxPool2d(kernel_size=2,stride=1,bias=use_bias),

            nn.Conv2d(512,512,kernel_size=2,stride=1,bias=use_bias),
            nn.ReLu(True)
            ]


        self.net = nn.Sequential(*self.net)
Пример #23
0
    def __init__(self,
                 input_channels,
                 hidden_channels,
                 kernel_size=3,
                 stride=1,
                 padding=0,
                 dilation=1,
                 hidden_kernel_size=1,
                 bias=True):

        super(ConvLSTMCell, self).__init__()
        self.input_channels = input_channels
        self.hidden_channels = hidden_channels

        self.kernel_size = _pair(kernel_size)
        self.stride = _pair(stride)
        self.padding = _pair(padding)
        self.dilation = _pair(dilation)

        self.hidden_kernel_size = _pair(hidden_kernel_size)

        hidden_padding = _pair(hidden_kernel_size // 2)

        gate_channels = 4 * self.hidden_channels
        self.conv_ih = nn.Conv2d(in_channels=self.input_channels,
                                 out_channels=gate_channels,
                                 kernel_size=self.kernel_size,
                                 stride=self.stride,
                                 padding=self.padding,
                                 dilation=self.dilation,
                                 bias=bias)

        self.conv_hh = nn.conv2d(in_channels=self.hidden_channels,
                                 out_channels=gate_channels,
                                 kernel_size=hidden_kernel_size,
                                 stride=1,
                                 padding=hidden_padding,
                                 dilation=1,
                                 bias=bias)

        self.reset_parameters()
    def __init__(self):
        super(VGG16, self).__init__()
        #network
        self.conv1 = nn.Conv2d(3, 64, padding=1, kernel_size=(3, 3), stride=1)
        #relu
        self.conv2 = nn.Conv2d(64, 64, padding=1, kernel_size=(3, 3), stride=1)
        #relu
        self.pool1 = nn.MaxPool2d((2, 2), stride=2)
        self.conv3 = nn.Conv2d(64,
                               128,
                               padding=1,
                               kernel_size=(3, 3),
                               stride=1)
        #relu
        self.conv4 = nn.Conv2d(128,
                               128,
                               padding=1,
                               kernel_size=(3, 3),
                               stride=1)
        #relu
        self.pool2 = nn.MaxPool2d((2, 2), stride=2)
        self.conv5 = nn.Conv2d(128,
                               256,
                               padding=1,
                               kernel_size=(3, 3),
                               stride=1)
        #relu
        self.conv6 = nn.Conv2d(256,
                               256,
                               padding=1,
                               kernel_size=(3, 3),
                               stride=1)
        #relu
        self.conv7 = nn.Conv2d(256,
                               256,
                               padding=1,
                               kernel_size=(3, 3),
                               stride=1)
        #relu
        self.pool3 = nn.MaxPool2d((2, 2), stride=2)
        self.conv8 = nn.Conv2d(256,
                               512,
                               padding=1,
                               kernel_size=(3, 3),
                               stride=1)
        #relu
        self.conv9 = nn.Conv2d(512,
                               512,
                               padding=1,
                               kernel_size=(3, 3),
                               stride=1)
        #relu
        self.conv10 = nn.conv2d(512,
                                512,
                                padding=1,
                                kernel_size=(3, 3),
                                stride=1)
        #relu
        self.pool4 = nn.MaxPool2d((2, 2), stride=2)
        self.conv11 = nn.conv2d(512,
                                512,
                                padding=1,
                                kernel_size=(3, 3),
                                stride=1)
        #relu
        self.conv12 = nn.conv2d(512,
                                512,
                                padding=1,
                                kernel_size=(3, 3),
                                stride=1)
        #relu
        self.conv13 = nn.conv2d(512,
                                512,
                                padding=1,
                                kernel_size=(3, 3),
                                stride=1)
        #relu
        self.pool5 = nn.MaxPool2d((2, 2), stride=2)
        self.linear1 = nn.Linear(7 * 7 * 512, 4096)
        #relu
        self.dropout = nn.Dropout(0.5)
        self.linear2 = nn.Linear(4096, 1000)
        #softmax

        self.default_optimizer = torch.optim.SGD(VGG16.parameters(),
                                                 lr=0.001,
                                                 momentum=0.9)
        self.default_loss = torch.nn.CrossEntropyLoss()
Пример #25
0
 def __init__(self, channel_in, kernel_size=3, stride=1, padding=1):
     self.conv = nn.conv2d(channel_in, channel_in, kernel_size=kernel_size,
                           stride=stride, padding=padding, groups=channel_in)
     self.norm = nn.BatchNorm2d(channel_in)
Пример #26
0
 def __init__(self, channel_in, channel_out, kernel_size=1,
              stride=1, padding=0):
     self.conv = nn.conv2d(channel_in, channel_out, kernel_size=kernel_size,
                           stride=stride, padding=padding)
     self.norm = nn.BatchNorm2d(channel_out)
Пример #27
0
 def forward(self, x, h, c):
     bsize, tsize, _, h, w = x.size()
     self.Wxi = nn.conv2d(1, self.hidden_layer, self.padding, self.stride)
Пример #28
0
 def __init__(self):
     super(fcn, self).__init__()
     self.layer1 = nn.sequential(
         nn.maxpool2d(kernel_size=(4, 4, 4)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3), dilation=(1, 2, 2)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3), dilation=(2, 4, 4)),
         nn.maxunpool2d(25, 25, kernel_size=(4, 4, 4)))
     self.layer2 = nn.sequential(
         nn.maxpool2d(kernel_size=(4, 4, 4)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3), dilation=(1, 2, 2)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3), dilation=(2, 4, 4)),
         nn.maxunpool2d(25, 25, kernel_size=(2, 2, 2)))
     self.layer3 = nn.sequential(
         nn.conv2d(3, 25, kernel_size=(3, 3, 3)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3), dilation=(1, 2, 2)),
         nn.conv2d(25, 25, kernel_size=(3, 3, 3), dilation=(2, 4, 4)))
     self.layer4 = nn.sequential(
         nn.conv2d(75, 75, kernel_size=(3, 3, 3), dilation=(2, 4, 4)),
         nn.conv2d(75, 100, kernel_size=(3, 3, 3), dilation=(2, 4, 4)),
         nn.conv2d(100, 100, kernel_size=(3, 3, 3), dilation=(2, 4, 4)),
         nn.conv2d(100, 100, kernel_size=(3, 3, 3), dilation=(2, 4, 4)),
         nn.conv2d(100, 2, kernel_size=(1, 1, 1)))
Пример #29
0
def conv1x1(inplanes, outplanes, stride=1):
    return nn.conv2d(inplanes, outplanes, kernel_size=1, stride=stride, padding=1, bias=False)