zoukankan      html  css  js  c++  java
  • HybridSN 高光谱分类网络的优化

    1.HybridSN 

    class HybridSN(nn.Module):
        def __init__(self):
            super(HybridSN, self).__init__()
            self.conv1 = nn.Conv3d(1, 8, (7, 3, 3), stride=1, padding=0)
            self.conv2 = nn.Conv3d(8, 16, (5, 3, 3), stride=1, padding=0)
            self.conv3 = nn.Conv3d(16, 32, (3, 3, 3), stride=1, padding=0)
            self.conv4 = nn.Conv2d(576, 64, kernel_size=3, stride=1, padding=0)
            self.bn1 = nn.BatchNorm2d(64)
            self.fc1 = nn.Linear(18496, 256)
            self.dropout1 = nn.Dropout(p=0.4)
            self.fc2 = nn.Linear(256, 128)
            self.dropout2 = nn.Dropout(p=0.4)
            self.fc3 = nn.Linear(128, class_num)
    
        def forward(self, x):
            out = self.conv1(x)
            out = self.conv2(out)
            out = self.conv3(out)
            #print(batch)
            out = out.reshape(batch, 576, 19, 19)
            out = self.conv4(out)
            out = self.bn1(out)
            out = F.relu(out)
            out = out.view(-1, 64 * 17 * 17)
            out = self.fc1(out)
            out = F.relu(out)
            out = self.dropout1(out)
            out = self.fc2(out)
            out = F.relu(out)
            out = self.dropout2(out)
            out = self.fc3(out)
            return out

    2.添加SENet

    class SELayer(nn.Module):
        def __init__(self, channel, r=16):
            super(SELayer, self).__init__()
            self.avg_pool = nn.AdaptiveAvgPool2d((1,1))
            self.fc = nn.Sequential(
                nn.Linear(channel, channel // r),
                nn.ReLU(),
                nn.Linear(channel // r, channel),
                nn.Sigmoid()
            )
    
        def forward(self, x):
            a, b, _, _ = x.size()
            y = self.avg_pool(x).view(a, b)
            y = self.fc(y).view(a, b, 1, 1)
            return x * y.expand_as(x)
    class HybridSN(nn.Module):
          def __init__(self, num_classes=16):
        '''
            self.senet = SELayer(64)
        '''
          def forward(self, x):
        '''
            out = self.conv3_2d(out)
            out = self.senet(out)
        '''

    3.为什么每次测试结果会不同

    Pytorch中,网络有train和eval两种模式

    在训练模式model.train() :启用 BatchNormalization 和 Dropout

    在测试模式model.eval() :不启用 BatchNormalization 和 Dropout

     可以看出训练模式和测试模式是不同的,导致我们在训练好的模型在每次测试中是不同的

  • 相关阅读:
    在MathType如何让括号随内容自动调整大小的技巧
    对于MathType中公式与文字错位的问题怎么解决
    怎样批量修改MathType公式格式
    你与论文达人只差一个MathType的距离
    公式达人必杀技,你会几招?
    如何用MathType快速输入公式
    openfire数据库mysql配置
    thinkphp 操作mssql2008
    phpstudy+php5.2+mssql2008
    thinkphp openfire 添加用户 骨架
  • 原文地址:https://www.cnblogs.com/yuzhenfu/p/13509743.html
Copyright © 2011-2022 走看看