-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path14-05-resnets.html
337 lines (227 loc) · 7.43 KB
/
14-05-resnets.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!DOCTYPE html>
<html>
<head>
<title>14.5 - ResNets [Andrei Bursuc]</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="./assets/katex.min.css">
<link rel="stylesheet" type="text/css" href="./assets/slides.css">
<link rel="stylesheet" type="text/css" href="./assets/grid.css">
</head>
<body>
<textarea id="source">
layout: true
.center.footer[Marc LELARGE and Andrei BURSUC | Deep Learning Do It Yourself | 14.5 ResNets]
---
class: center, middle, title-slide
count: false
## Going Deeper
# 14.5 ResNets
<br/>
<br/>
.bold[Andrei Bursuc ]
<br/>
url: https://dataflowr.github.io/website/
.citation[
With slides from A. Karpathy, F. Fleuret, G. Louppe, C. Ollion, O. Grisel, Y. Avrithis ...]
---
class: middle, center
## How deep can we go now?
---
# A saturation point
If we continue stacking more layers on a CNN:
.center.width-90[]
--
count: false
.center[.red[Deeper models are harder to optimize]]
---
.left-column[
# ResNet
]
.right-column[
.center.width-50[]
]
A block learns the residual w.r.t. identity
.center.width-40[]
.citation[K. He et al., Deep residual learning for image recognition, CVPR 2016.]
--
count: false
- Good optimization properties
---
.left-column[
# ResNet
]
.right-column[
.center.width-50[]
]
Even deeper models:
34, 50, 101, 152 layers
.citation[K. He et al., Deep residual learning for image recognition, CVPR 2016.]
---
.left-column[
# ResNet
]
.right-column[
.center.width-50[]
]
ResNet50 Compared to VGG:
- Superior accuracy in all vision tasks <br/>**5.25%** top-5 error vs 7.1%
.citation[K. He et al., Deep residual learning for image recognition, CVPR 2016.]
--
count: false
- Less parameters <br/>**25M** vs 138M
--
count: false
- Computational complexity <br/>**3.8B Flops** vs 15.3B Flops
--
count: false
- Fully Convolutional until the last layer
---
# ResNet
## Performance on ImageNet
.center.width-90[]
---
# ResNet
## Results
.center.width-100[]
---
# ResNet
## Results
.center.width-60[]
---
# ResNet
In PyTorch:
```py
def make_resnet_block(num_feature_maps , kernel_size = 3):
return nn.Sequential(
nn.Conv2d(num_feature_maps , num_feature_maps ,
kernel_size = kernel_size ,
padding = (kernel_size - 1) // 2),
nn.BatchNorm2d(num_feature_maps),
nn.ReLU(inplace = True),
nn.Conv2d(num_feature_maps , num_feature_maps ,
kernel_size = kernel_size ,
padding = (kernel_size - 1) // 2),
nn.BatchNorm2d(num_feature_maps),
)
```
---
# ResNet
In PyTorch:
```py
def __init__(self, num_residual_blocks, num_feature_maps)
...
self.resnet_blocks = nn.ModuleList()
for k in range(nb_residual_blocks):
self.resnet_blocks.append(make_resnet_block(num_feature_maps , 3))
...
```
```py
def forward(self,x):
...
for b in self.resnet_blocks:
* x = x + b(x)
...
return x
```
---
For ResNet50+ layers some additional modifications need to be made to keep number of parameters and computations manageable
.center.width-70[]
Such a block requires $2 \times (3 \times 3 \times 256 +1) \times 256 \simeq 1.2M$ parameters
.credit[Credits: F. Fleuret, [EE-559 Deep Learning](https://fleuret.org/dlc/), EPFL]
--
count: false
Adress this problem using __bottleneck__ block
.center.width-100[]
.center[$256 \times 64 + (3 \times 3 \times 64 +1) \times 64 + 64 \times 256 \simeq 70K$ parameters]
---
# Stochastic Depth Networks
- DropOut at layer level
- Allows training up to 1K layers
.center.width-70[]
.citation[Huang et al., Deep Networks with Stochastic Depth, ECCV 2016]
---
# DenseNet
- Copying feature maps to upper layers via skip-connections
- Better reuse of parameters and redundancy avoidance
.center.width-30[]
.center.width-70[]
.citation[Huang et al., Densely Connected Convolutional Networks, CVPR 2017]
---
# Visualizing loss surfaces
.center.width-70[]
.citation[H. Li et al., Visualizing the Loss Landscape of Neural Nets, ICLR workshop 2018]
---
# Visualizing loss surfaces
.left-column[
.center.width-100[]
]
.right-column[
<br><br><br><br><br>
- ResNet-20/56/110 : vanilla
- ResNet-*-noshort: no skip connections
- ResNet-18/34/50 : wide
]
.citation[H. Li et al., Visualizing the Loss Landscape of Neural Nets, ICLR workshop 2018]
---
# Visualizing loss surfaces
.center.width-50[]
.citation[H. Li et al., Visualizing the Loss Landscape of Neural Nets, ICLR workshop 2018]
---
# Outline
## Universal approximation theorem
## Why going deeper?
## Regularization in deep networks
### classic regularization: $L\_2$ regularization
### implicit regularization: Dropout, Batch Normalization
## Residual networks
---
class: end-slide, center
count: false
The end.
</textarea>
<script src="./assets/remark-latest.min.js"></script>
<script src="./assets/auto-render.min.js"></script>
<script src="./assets/katex.min.js"></script>
<script type="text/javascript">
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// var options = {sourceUrl: getParameterByName("p"),
// highlightLanguage: "python",
// // highlightStyle: "tomorrow",
// // highlightStyle: "default",
// highlightStyle: "github",
// // highlightStyle: "googlecode",
// // highlightStyle: "zenburn",
// highlightSpans: true,
// highlightLines: true,
// ratio: "16:9"};
var options = {sourceUrl: getParameterByName("p"),
highlightLanguage: "python",
highlightStyle: "github",
highlightSpans: true,
highlightLines: true,
ratio: "16:9",
slideNumberFormat: (current, total) => `
<div class="progress-bar-container">${current}/${total} <br/><br/>
<div class="progress-bar" style="width: ${current/total*100}%"></div>
</div>
`};
var renderMath = function() {
renderMathInElement(document.body, {delimiters: [ // mind the order of delimiters(!?)
{left: "$$", right: "$$", display: true},
{left: "$", right: "$", display: false},
{left: "\\[", right: "\\]", display: true},
{left: "\\(", right: "\\)", display: false},
]});
}
var slideshow = remark.create(options, renderMath);
</script>
</body>
</html>