第五周作业:卷积神经网络(part3)

一、《MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications》

MobileNet是Google提出的一种小巧而高效的CNN模型,其在accuracy和latency之间做了折中。

MobileNet的基本单元是深度级可分离卷积。深度级可分离卷积其实是一种可分解卷积操作,其可以分解为两个更小的操作:depthwise convolution和pointwise convolution。Depthwise convolution和标准卷积不同,对于标准卷积其卷积核是用在所有的输入通道上,而depthwise convolution针对每个输入通道采用不同的卷积核,就是说一个卷积核对应一个输入通道,所以说depthwise convolution是depth级别的操作。而pointwise convolution其实就是普通的卷积,只不过其采用1x1的卷积核。对于depthwise separable convolution,其首先是采用depthwise convolution对不同输入通道分别进行卷积,然后采用pointwise convolution将上面的输出再进行结合,这样其实整体效果和一个标准卷积是差不多的,但是会大大减少计算量和模型参数量。

 

 

 

 

二、《MobileNetV2: Inverted Residuals and Linear Bottlenecks》

MobileNetV2是在V1基础之上的改进。

 

MobileNetV2添加了残差学习的思想(inverted residual倒残差结构)。

inverted residual block是先升维,再降维。MobileNetV2降低了参数的数量和计算复杂度,增强了梯度的传播。

 

 

 

三、《HybridSN: Exploring 3D-2D CNN Feature Hierarchy for Hyperspectral Image Classification》

HybridSN模型将3D-CNN和2D-CNN层结合到了一起,该模型首先进行降维操作,然后是3层三维卷积 → 1层二维卷积→ 2层全连接层→ 1层softmax分类层。


网络模型:

 

网络代码:

class HybridSN(nn.Module):
  def __init__(self):
    super(HybridSN, self).__init__()
    self.conv3d_1 = nn.Sequential(
        nn.Conv3d(1, 8, kernel_size=(7, 3, 3), stride=1, padding=0),
        nn.BatchNorm3d(8),
        nn.ReLU(inplace = True),
    )
    self.conv3d_2 = nn.Sequential(
        nn.Conv3d(8, 16, kernel_size=(5, 3, 3), stride=1, padding=0),
        nn.BatchNorm3d(16),
        nn.ReLU(inplace = True),
    ) 
    self.conv3d_3 = nn.Sequential(
        nn.Conv3d(16, 32, kernel_size=(3, 3, 3), stride=1, padding=0),
        nn.BatchNorm3d(32),
        nn.ReLU(inplace = True)
    )

    self.conv2d_4 = nn.Sequential(
        nn.Conv2d(576, 64, kernel_size=(3, 3), stride=1, padding=0),
        nn.BatchNorm2d(64),
        nn.ReLU(inplace = True),
    )
    self.fc1 = nn.Linear(18496,256)
    self.fc2 = nn.Linear(256,128)
    self.fc3 = nn.Linear(128,16)
    self.dropout = nn.Dropout(p = 0.4)

  def forward(self,x):
    out = self.conv3d_1(x)
    out = self.conv3d_2(out)
    out = self.conv3d_3(out)
    out = self.conv2d_4(out.reshape(out.shape[0],-1,19,19))
    out = out.reshape(out.shape[0],-1)
    out = F.relu(self.dropout(self.fc1(out)))
    out = F.relu(self.dropout(self.fc2(out)))
    out = self.fc3(out)
    return out

执行结果:

 

 

posted @ 2021-10-04 00:08  梁森  阅读(97)  评论(0)    收藏  举报