Exemple #1
0
class CNN(nn.Module):
  
  def __init__(nn.Module):
    super(CNN, self).__init__(self, n_classes)
    self.features = nn.Sequential(
       nn.Conv2d(3, 64, kernel_size = 11, stride = 4, padding = 2),
       nn.ReLU(),
       nn.Maxpool2d(kernel_size = 3, stride = 2),
       nn.Conv2d(64, 192, kernel_size = 3, padding = 1),
       nn.ReLU(),
       nn.Maxpool2d(kernel_size = 3, stride = 2),       
       nn.Conv2d(192, 256, kernel_size = 3, padding = 1),
       nn.ReLU(),
       nn.Maxpool2d(kernel_size = 3, stride = 2),
       nn.Conv2d(256, 256, kernel_size = 3, padding = 1),
       nn.ReLU(),
       nn.Maxpool2d(kernel_size = 3, stride = 2),       
    )
    self.avgpool = nn.AdaptiveAvegPool2d((6,6))
    self.classifier = nn.Sequential(
      nn.Dropout(),
      nn.Linear(256*6*6, 4096)
      nn.ReLU(),
      nn.Dropout(),
      nn.Linear(4096, 4096),
      nn.ReLU(),
      nn.Linear(4096, n_classes)
    )  
Exemple #2
0
    def __init__(self):
        super(LeNet, self).__init__()

        layer1 = nn.Sequential()
        layer1.add_module('conv1', nn.Conv2d(1, 6, 3, padding=1))
        layer1.add_module('pool1', nn.Maxpool2d(2, 2))
        self.layer1 = layer1

        layer2 = nn.Sequential()
        layer2.add_module('conv2', nn.Conv2d(6, 16, 5))
        layer2.add_module('pool2', nn.Maxpool2d(2, 2))
        self.layer2 = layer2

        layer3 = nn.Sequential()
        layer3.add_module('fc1', nn.Linear(400, 120))
        layer3.add_module('fc2', nn.Linear(120, 84))
        layer3.add_module('fc3', nn.Linear(84, 10))
        self.layer3 = layer3

        def forward(self, x):
            x = self.layer1(x)
            x = self.layer2(x)
            x = x.view(x.size(0), -1)
            x = self.layer3(x)
            return x
def create_stem(channels):
    stem = nn.Sequential()
    stem.add_module('conv1', conv_bn_relu(in_channels=3, out_channels=channels[0], kernel_size=11, stride=4, padding=2))
    stem.add_module('maxpool1', nn.Maxpool2d(kernel_size=3, stride=2))
    stem.add_module('conv2', conv_bn_relu(in_channels=channels[0], out_channels=channels[1], kernel_size=5, padding=2))
    stem.add_module('maxpool2', nn.Maxpool2d(kernel_size=3, stride=2))
    stem.add_module('conv3', conv_bn_relu(in_channels=channels[1], out_channels=channels[2], kernel_size=3, padding=1))
    stem.add_module('conv4', conv_bn_relu(in_channels=channels[2], out_channels=channels[3], kernel_size=3, padding=1))
    stem.add_module('conv5', conv_bn_relu(in_channels=channels[3], out_channels=channels[4], kernel_size=3, padding=1))
    stem.add_module('maxpool3', nn.Maxpool2d(kernel_size=3, stride=2))
    return stem
Exemple #4
0
    def __init__(self, h, m, k, n, hidden_size):
        super().__init__()
        self.h = h # filter length
        self.m = m # filter width
        self.k = k # phoneme vector size
        self.n = n # word length
        self.p = k - h + 1
        self.q = n - m + 1
        self.stride = 2

        self.conv_1 = nn.Conv2d(in_channels=1, out_channels=self.p*self.q, kernel_size=(h, m))
        self.conv_2 = nn.Conv2d(in_channels=self.p*self.q, out_channels=self.p*self.q, kernel_size=(h, m))
        self.conv_3 = nn.Conv2d(in_channels=self.p*self.q, out_channels=self.p*self.q, kernel_size=(h, m))
        self.maxpool = nn.Maxpool2d((self.p, self.q), stride=self.stride)
        self.manhattan = ef.manhattan_distance

        self.input_layer = nn.Linear(7, hidden_size)
        self.hidden_1 = nn.Linear(hidden_size, hidden_size)
        self.hidden_2 = nn.Linear(hidden_size, hidden_size)
        self.hidden_3 = nn.Linear(hidden_size, hidden_size)

        self.output = nn.Linear(hidden_size, 1)

        self.sigmoid = nn.Sigmoid()
        self.softmax = nn.Softmax(dim=1)
Exemple #5
0
    def __init__(self, img_channels, num_layers):
        super(self).__init__()

        self.vgg_block_1 = self._make_vgg_block(img_channels, 64, num_layers[0])
        self.maxpool_1 = nn.Maxpool2d(stride=2, padding=2)
        self.vgg_block_2 = self._make_vgg_block(64, 128, num_layers[1])
        self.maxpool_2 = nn.Maxpool2d(stride=2, padding=2)
        self.vgg_block_3 = self._make_vgg_block(128, 256, num_layers[2])
        self.maxpool_3 = nn.Maxpool2d(stride=2, padding=2)
        self.vgg_block_4 = self._make_vgg_block(256, 512, num_layers[3])
        self.maxpool_4 = nn.Maxpool2d(stride=2, padding=2)
        self.vgg_block_5 = self._make_vgg_block(512, 512, num_layers[4])
        self.maxpool_5 = nn.Maxpool2d(stride=2, padding=2)

        self.linear_1 = nn.Linear(512*7*7, 4096)
        self.linear_2 = nn.Linear(4096, 4096)
        self.linear_3 = nn.Linear(4096, 1000)
Exemple #6
0
	def __init__(self):
		super().__init__()
		Conv = ConvWarpper
		self.conv1 = Conv(3, 16, 3, padding=1, relu=True, batch_norm=False)
		self.pool1 = nn.MaxPool2d(2, 2)
		self.conv2 = Conv(16, 32, 3, padding=1, relu=True, batch_norm=True)
		self.pool2 = nn.Maxpool2d(2, 2)
		self.conv3_1s = Conv(32, 16, 1, padding=0, relu=False, batch_norm=False)
		self.conv3_1 = Conv(16, 128, 3, padding=1, relu=True, batch_norm=False)
		self.conv3_2s = Conv(128, 16, 1, padding=0, relu=False, batch_norm=False)
		self.conv3_2 = Conv(16, 128, 3, padding=1, relu=True, batch_norm=True)
		self.pool3 = nn.Maxpool2d(2, 2)
		self.conv4_1s = Conv(128, 32, 1, padding=0, relu=False, batch_norm=False)
		self.conv4_1 = Conv(32, 256, 3, padding=1, relu=True, batch_norm=False)
		self.conv4_2s = Conv(256, 32, 1, padding=0, relu=False, batch_norm=False)
		self.conv4_2 = Conv(32, 256, 3, padding=1, relu=True, batch_norm=True)
		self.pool4 = nn.Maxpool2d(2, 2)
		self.conv5_1s = Conv(256, 64, 1, padding=0, relu=False, batch_norm=False)
		self.conv5_1 = Conv(64, 512, 3, padding=1, relu=True, batch_norm=False)
Exemple #7
0
    def __init__(self, base=4):
        self.base = base
        super(ConvNet, self).__init__()

        self.conv1 = nn.Conv2d(1, 2**self.base, kernel_size=3, padding=1)
        self.conv2 = nn.Conv2d(2**self.base,
                               2**self.base,
                               kernel_size=3,
                               padding=1)

        self.conv3 = nn.Conv2d(2**self.base,
                               2**(self.base + 1),
                               kernel_size=3,
                               padding=1)
        self.conv4 = nn.Conv2d(2**(self.base + 1),
                               2**(self.base + 1),
                               kernel_size=3,
                               padding=1)

        self.conv5 = nn.Conv2d(2**(self.base + 1),
                               2**(self.base + 2),
                               kernel_size=3,
                               padding=1)
        self.conv6 = nn.Conv2d(2**(self.base + 2),
                               2**(self.base + 2),
                               kernel_size=3,
                               padding=1)

        self.conv7 = nn.Conv2d(2**(self.base + 2),
                               2**(self.base + 3),
                               kernel_size=3,
                               padding=1)
        self.conv8 = nn.Conv2d(2**(self.base + 3),
                               2**(self.base + 3),
                               kernel_size=3,
                               padding=1)

        self.conv9 = nn.Conv2d(2**(self.base + 3),
                               2**(self.base + 4),
                               kernel_size=3,
                               padding=1)
        self.conv10 = nn.Conv2d(2**(self.base + 4),
                                2**(self.base + 4),
                                kernel_size=3,
                                padding=1)

        self.pool = nn.Maxpool2d(kernel_size=2)

        self.linear1 = nn.Linear(2048, 1024)
        self.linear2 = nn.Linear(1024, 512)
        self.linear3 = nn.Linear(512, 1)

        self.dropout1 = nn.Dropout(0.5)
        self.dropout2 = nn.Dropout(0.3)
Exemple #8
0
    def __init__(self,
                CT_embedding_dim = 32,
                other_imformation_dim=64,
                FVC_imformation_dim =64,
                CT_imformation_dim=64,
    ):

        super(baseline_predict_model, self).__init__()

        self.CT_feather_model = CT_feather()

        self.CT_conv = nn.Sequential(
            nn.Conv2d(CT_embedding_dim,CT_imformation_dim,1),
            nn.ReLU(),
            nn.Dropout(p=0.5)
        )

        self.fvc_linear = nn.Sequential(
            nn.Linear(146, FVC_imformation_dim),
            nn.ReLU(),
            nn.Dropout(p=0.5))

        self.other_imfor_linear = nn.Sequential(
            nn.Linear(3, other_imformation_dim),
            nn.ReLU(),
            nn.Dropout(p=0.5))


        pointwise_in_channels = other_imformation_dim + FVC_imformation_dim + CT_imformation_dim
        self.pointwise = nn.Sequential(
            nn.Conv2d(pointwise_in_channels,32,1),
            nn.Conv2d(32,16,1),
            nn.Conv2d(16,8,1),
            nn.ReLU(),
            nn.Dropout(p=0.5)
        )

        self.output_layer == nn.Sequential(
            nn.Maxpool2d((5,1))
            nn.Linear(146,146)
        )