标签:链接 cin lin elf 区间 border 基于 color ios
最近在利用SSD检测物体时,由于实际项目要求,需要对模型进行轻量化,所以考虑利用轻量网络替换原本的骨架VGG16,查找一些资料后最终采用了google开源的mobileNetV2。这里对学习mobileNet系列的过程做一些总结
mobileNetV1是由google在2017年发布的一个轻量级深度神经网络,其主要特点是采用深度可分离卷积替换了普通卷积,2018年提出的mobileNetV2在V1的基础上引入了线性瓶颈 (Linear Bottleneck)和倒残差 (Inverted Residual)来提高网络的表征能力。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
import torch import torch.nn as nn def conv3x3(in_planes, out_planes, stride = 1 , padding = 1 ): return nn.Conv2d(in_planes, out_planes, kernel_size = 3 , stride = stride, padding = padding, bias = False ) # why no bias: 如果卷积层之后是BN层,那么可以不用偏置参数,可以节省内存 def conv1x1(in_planes, out_planes): return nn.Conv2d(in_planes, out_planes, kernel_size = 1 , stride = 1 , bias = False ) class DPBlock(nn.Module): ‘‘‘ Depthwise convolution and Pointwise convolution. ‘‘‘ def __init__( self , in_planes, out_planes, stride = 1 ): super (DPBlock, self ).__init__() # 调用基类__init__函数初始化 self .conv1 = conv3x3(in_planes, out_planes, stride) self .bn1 = nn.BatchNorm2d(in_planes) self .relu = nn.ReLU(inplace = True ) self .conv2 = conv1x1(in_planes, out_planes) self .bn2 = nn.BatchNorm2d(out_planes) def forward( self , x): out = self .conv1(x) out = self .bn1(out) out = self .relu(out) out = self .conv2(out) out = self .bn2(out) out = self .relu(out) return out class mobileNetV1Net(nn.Module): def __init__( self , block, num_class = 1000 ): super (mobileNetV1Net, self ).__init__() self .model = nn.Sequential( conv3x3( 3 , 32 , 2 ), nn.BatchNorm2d( 32 ), nn.ReLU(inplace = True ) block( 32 , 64 , 1 ), block( 64 , 128 , 2 ), block( 128 , 128 , 1 ), block( 128 , 256 , 2 ), block( 256 , 256 , 1 ), block( 256 , 512 , 2 ), block( 512 , 512 , 1 ), block( 512 , 512 , 1 ), block( 512 , 512 , 1 ), block( 512 , 512 , 1 ), block( 512 , 512 , 1 ), block( 512 , 1024 , 2 ), block( 1024 , 1024 , 2 ), nn.AvgPool2d( 7 ) ) self .fc = nn.Linear( 1024 , num_class) def forward( self , x): x = self .model(x) x = x.view( - 1 , 1024 ) # reshape out = self .fc(x) return out mobileNetV1 = mobileNetV1Net(DPBlock) |
标签:链接 cin lin elf 区间 border 基于 color ios
原文地址:https://www.cnblogs.com/gfghkoiygcb/p/12507573.html