ResNet

class paddle.vision.models. ResNet ( block, depth=50, width=64, num_classes=1000, with_pool=True, groups=1 ) [source]

ResNet model from “Deep Residual Learning for Image Recognition”.

Parameters
  • Block (BasicBlock|BottleneckBlock) – Block module of model.

  • depth (int, optional) – Layers of ResNet, Default: 50.

  • width (int, optional) – Base width per convolution group for each convolution block, Default: 64.

  • num_classes (int, optional) – Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000.

  • with_pool (bool, optional) – Use pool before the last fc layer or not. Default: True.

  • groups (int, optional) – Number of groups for each convolution block, Default: 1.

Returns

Layer. An instance of ResNet model.

Examples

>>> import paddle
>>> from paddle.vision.models import ResNet
>>> from paddle.vision.models.resnet import BottleneckBlock, BasicBlock

>>> # build ResNet with 18 layers
>>> resnet18 = ResNet(BasicBlock, 18)

>>> # build ResNet with 50 layers
>>> resnet50 = ResNet(BottleneckBlock, 50)

>>> # build Wide ResNet model
>>> wide_resnet50_2 = ResNet(BottleneckBlock, 50, width=64*2)

>>> # build ResNeXt model
>>> resnext50_32x4d = ResNet(BottleneckBlock, 50, width=4, groups=32)

>>> x = paddle.rand([1, 3, 224, 224])
>>> out = resnet18(x)

>>> print(out.shape)
[1, 1000]
forward ( x )

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments