3333 '02f35f034ca3858e1e54d4036443c92d' ),
3434 'resnet152' : ('https://paddle-hapi.bj.bcebos.com/models/resnet152.pdparams' ,
3535 '7ad16a2f1e7333859ff986138630fd7a' ),
36+ 'wide_resnet50_2' :
37+ ('https://bj.bcebos.com/v1/ai-studio-online/93f78b51775a4434bde046e765a206c51b1aa05797c64f96aff33f7791b3de45' ,
38+ '0282f804d73debdab289bd9fea3fa6dc' ),
39+ 'wide_resnet101_2' :
40+ ('https://bj.bcebos.com/v1/ai-studio-online/cfb1df23c8604dbfa0c52aacdc841810901fa064ff104abda62bfb112b022245' ,
41+ 'd4360a2d23657f059216f5d5a1a9ac93' )
3642}
3743
3844
@@ -153,23 +159,36 @@ class ResNet(nn.Layer):
153159 Args:
154160 Block (BasicBlock|BottleneckBlock): block module of model.
155161 depth (int): layers of resnet, default: 50.
156- num_classes (int): output dim of last fc layer. If num_classes <=0, last fc layer
162+ width (int): base width of resnet, default: 64.
163+ num_classes (int): output dim of last fc layer. If num_classes <=0, last fc layer
157164 will not be defined. Default: 1000.
158165 with_pool (bool): use pool before the last fc layer or not. Default: True.
159166
160167 Examples:
161168 .. code-block:: python
162-
169+ import paddle
163170 from paddle.vision.models import ResNet
164171 from paddle.vision.models.resnet import BottleneckBlock, BasicBlock
165172
166173 resnet50 = ResNet(BottleneckBlock, 50)
167174
175+ wide_resnet50_2 = ResNet(BottleneckBlock, 50, width=64*2)
176+
168177 resnet18 = ResNet(BasicBlock, 18)
169178
179+ x = paddle.rand([1, 3, 224, 224])
180+ out = resnet18(x)
181+
182+ print(out.shape)
183+
170184 """
171185
172- def __init__ (self , block , depth , num_classes = 1000 , with_pool = True ):
186+ def __init__ (self ,
187+ block ,
188+ depth = 50 ,
189+ width = 64 ,
190+ num_classes = 1000 ,
191+ with_pool = True ):
173192 super (ResNet , self ).__init__ ()
174193 layer_cfg = {
175194 18 : [2 , 2 , 2 , 2 ],
@@ -179,6 +198,8 @@ def __init__(self, block, depth, num_classes=1000, with_pool=True):
179198 152 : [3 , 8 , 36 , 3 ]
180199 }
181200 layers = layer_cfg [depth ]
201+ self .groups = 1
202+ self .base_width = width
182203 self .num_classes = num_classes
183204 self .with_pool = with_pool
184205 self ._norm_layer = nn .BatchNorm2D
@@ -225,11 +246,17 @@ def _make_layer(self, block, planes, blocks, stride=1, dilate=False):
225246
226247 layers = []
227248 layers .append (
228- block (self .inplanes , planes , stride , downsample , 1 , 64 ,
229- previous_dilation , norm_layer ))
249+ block (self .inplanes , planes , stride , downsample , self . groups ,
250+ self . base_width , previous_dilation , norm_layer ))
230251 self .inplanes = planes * block .expansion
231252 for _ in range (1 , blocks ):
232- layers .append (block (self .inplanes , planes , norm_layer = norm_layer ))
253+ layers .append (
254+ block (
255+ self .inplanes ,
256+ planes ,
257+ groups = self .groups ,
258+ base_width = self .base_width ,
259+ norm_layer = norm_layer ))
233260
234261 return nn .Sequential (* layers )
235262
@@ -268,100 +295,185 @@ def _resnet(arch, Block, depth, pretrained, **kwargs):
268295
269296
270297def resnet18 (pretrained = False , ** kwargs ):
271- """ResNet 18-layer model
272-
298+ """ResNet 18-layer model from
299+ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
300+
273301 Args:
274302 pretrained (bool): If True, returns a model pre-trained on ImageNet
275303
276304 Examples:
277305 .. code-block:: python
278-
306+ import paddle
279307 from paddle.vision.models import resnet18
280308
281309 # build model
282310 model = resnet18()
283311
284312 # build model and load imagenet pretrained weight
285313 # model = resnet18(pretrained=True)
314+
315+ x = paddle.rand([1, 3, 224, 224])
316+ out = model(x)
317+
318+ print(out.shape)
286319 """
287320 return _resnet ('resnet18' , BasicBlock , 18 , pretrained , ** kwargs )
288321
289322
290323def resnet34 (pretrained = False , ** kwargs ):
291- """ResNet 34-layer model
292-
324+ """ResNet 34-layer model from
325+ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
326+
293327 Args:
294328 pretrained (bool): If True, returns a model pre-trained on ImageNet
295-
329+
296330 Examples:
297331 .. code-block:: python
298-
332+ import paddle
299333 from paddle.vision.models import resnet34
300334
301335 # build model
302336 model = resnet34()
303337
304338 # build model and load imagenet pretrained weight
305339 # model = resnet34(pretrained=True)
340+
341+ x = paddle.rand([1, 3, 224, 224])
342+ out = model(x)
343+
344+ print(out.shape)
306345 """
307346 return _resnet ('resnet34' , BasicBlock , 34 , pretrained , ** kwargs )
308347
309348
310349def resnet50 (pretrained = False , ** kwargs ):
311- """ResNet 50-layer model
312-
350+ """ResNet 50-layer model from
351+ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
352+
313353 Args:
314354 pretrained (bool): If True, returns a model pre-trained on ImageNet
315355
316356 Examples:
317357 .. code-block:: python
318-
358+ import paddle
319359 from paddle.vision.models import resnet50
320360
321361 # build model
322362 model = resnet50()
323363
324364 # build model and load imagenet pretrained weight
325365 # model = resnet50(pretrained=True)
366+
367+ x = paddle.rand([1, 3, 224, 224])
368+ out = model(x)
369+
370+ print(out.shape)
326371 """
327372 return _resnet ('resnet50' , BottleneckBlock , 50 , pretrained , ** kwargs )
328373
329374
330375def resnet101 (pretrained = False , ** kwargs ):
331- """ResNet 101-layer model
332-
376+ """ResNet 101-layer model from
377+ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
378+
333379 Args:
334380 pretrained (bool): If True, returns a model pre-trained on ImageNet
335381
336382 Examples:
337383 .. code-block:: python
338-
384+ import paddle
339385 from paddle.vision.models import resnet101
340386
341387 # build model
342388 model = resnet101()
343389
344390 # build model and load imagenet pretrained weight
345391 # model = resnet101(pretrained=True)
392+
393+ x = paddle.rand([1, 3, 224, 224])
394+ out = model(x)
395+
396+ print(out.shape)
346397 """
347398 return _resnet ('resnet101' , BottleneckBlock , 101 , pretrained , ** kwargs )
348399
349400
350401def resnet152 (pretrained = False , ** kwargs ):
351- """ResNet 152-layer model
352-
402+ """ResNet 152-layer model from
403+ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_
404+
353405 Args:
354406 pretrained (bool): If True, returns a model pre-trained on ImageNet
355407
356408 Examples:
357409 .. code-block:: python
358-
410+ import paddle
359411 from paddle.vision.models import resnet152
360412
361413 # build model
362414 model = resnet152()
363415
364416 # build model and load imagenet pretrained weight
365417 # model = resnet152(pretrained=True)
418+
419+ x = paddle.rand([1, 3, 224, 224])
420+ out = model(x)
421+
422+ print(out.shape)
366423 """
367424 return _resnet ('resnet152' , BottleneckBlock , 152 , pretrained , ** kwargs )
425+
426+
427+ def wide_resnet50_2 (pretrained = False , ** kwargs ):
428+ """Wide ResNet-50-2 model from
429+ `"Wide Residual Networks" <https://arxiv.org/pdf/1605.07146.pdf>`_.
430+
431+ Args:
432+ pretrained (bool): If True, returns a model pre-trained on ImageNet
433+
434+ Examples:
435+ .. code-block:: python
436+ import paddle
437+ from paddle.vision.models import wide_resnet50_2
438+
439+ # build model
440+ model = wide_resnet50_2()
441+
442+ # build model and load imagenet pretrained weight
443+ # model = wide_resnet50_2(pretrained=True)
444+
445+ x = paddle.rand([1, 3, 224, 224])
446+ out = model(x)
447+
448+ print(out.shape)
449+ """
450+ kwargs ['width' ] = 64 * 2
451+ return _resnet ('wide_resnet50_2' , BottleneckBlock , 50 , pretrained , ** kwargs )
452+
453+
454+ def wide_resnet101_2 (pretrained = False , ** kwargs ):
455+ """Wide ResNet-101-2 model from
456+ `"Wide Residual Networks" <https://arxiv.org/pdf/1605.07146.pdf>`_.
457+
458+ Args:
459+ pretrained (bool): If True, returns a model pre-trained on ImageNet
460+
461+ Examples:
462+ .. code-block:: python
463+ import paddle
464+ from paddle.vision.models import wide_resnet101_2
465+
466+ # build model
467+ model = wide_resnet101_2()
468+
469+ # build model and load imagenet pretrained weight
470+ # model = wide_resnet101_2(pretrained=True)
471+
472+ x = paddle.rand([1, 3, 224, 224])
473+ out = model(x)
474+
475+ print(out.shape)
476+ """
477+ kwargs ['width' ] = 64 * 2
478+ return _resnet ('wide_resnet101_2' , BottleneckBlock , 101 , pretrained ,
479+ ** kwargs )
0 commit comments