ResNet¶
Feature Extraction Link¶
ResNet¶

class
chainercv.links.model.resnet.
ResNet
(n_layer, n_class=None, pretrained_model=None, mean=None, initialW=None, fc_kwargs={}, arch='fb')[source]¶ Base class for ResNet architecture.
This is a pickable sequential link. The network can choose output layers from set of all intermediate layers. The attribute
pick
is the names of the layers that are going to be picked by__call__()
. The attributelayer_names
is the names of all layers that can be picked.Examples
>>> model = ResNet50() # By default, __call__ returns a probability score (after Softmax). >>> prob = model(imgs) >>> model.pick = 'res5' # This is layer res5 >>> res5 = model(imgs) >>> model.pick = ['res5', 'fc6'] >>> # These are layers res5 and fc6. >>> res5, fc6 = model(imgs)
See also
chainercv.links.model.PickableSequentialChain
When
pretrained_model
is the path of a pretrained chainer model serialized as anpz
file in the constructor, this chain model automatically initializes all the parameters with it. When a string in the prespecified set is provided, a pretrained model is loaded from weights distributed on the Internet. The list of pretrained models supported are as follows:imagenet
: Loads weights trained with ImageNet. Whenarch=='he'
, the weights distributed at Model Zoo are used.
 Parameters
n_layer (int) – The number of layers.
n_class (int) – The number of classes. If
None
, the default values are used. If a supported pretrained model is used, the number of classes used to train the pretrained model is used. Otherwise, the number of classes in ILSVRC 2012 dataset is used.pretrained_model (string) – The destination of the pretrained chainer model serialized as a
npz
file. If this is one of the strings described above, it automatically loads weights stored under a directory$CHAINER_DATASET_ROOT/pfnet/chainercv/models/
, where$CHAINER_DATASET_ROOT
is set as$HOME/.chainer/dataset
unless you specify another value by modifying the environment variable.mean (numpy.ndarray) – A mean value. If
None
, the default values are used. If a supported pretrained model is used, the mean value used to train the pretrained model is used. Otherwise, the mean value calculated from ILSVRC 2012 dataset is used.initialW (callable) – Initializer for the weights of convolution kernels.
fc_kwargs (dict) – Keyword arguments passed to initialize the
chainer.links.Linear
.arch (string) – If
fb
, use Facebook ResNet architecture. Whenhe
, use the architecture presented by the original ResNet paper. This option changes where to apply strided convolution. The default value isfb
.
ResNet50¶
ResNet101¶
Utility¶
Bottleneck¶

class
chainercv.links.model.resnet.
Bottleneck
(in_channels, mid_channels, out_channels, stride=1, dilate=1, groups=1, initialW=None, bn_kwargs={}, residual_conv=False, stride_first=False, add_seblock=False)[source]¶ A bottleneck layer.
 Parameters
in_channels (int) – The number of channels of the input array.
mid_channels (int) – The number of channels of intermediate arrays.
out_channels (int) – The number of channels of the output array.
stride (int or tuple of ints) – Stride of filter application.
dilate (int or tuple of ints) – Dilation factor of filter applications.
dilate=d
anddilate=(d, d)
are equivalent.groups (int) – The number of groups to use grouped convolution in the second layer. The default is one, where grouped convolution is not used.
initialW (callable) – Initial weight value used in the convolutional layers.
bn_kwargs (dict) – Keyword arguments passed to initialize
chainer.links.BatchNormalization
.residual_conv (bool) – If
True
, apply a 1x1 convolution to the residual.stride_first (bool) – If
True
, apply strided convolution with the first convolution layer. Otherwise, apply strided convolution with the second convolution layer.add_seblock (bool) – If
True
, apply a squeezeandexcitation block to each residual block.
ResBlock¶

class
chainercv.links.model.resnet.
ResBlock
(n_layer, in_channels, mid_channels, out_channels, stride, dilate=1, groups=1, initialW=None, bn_kwargs={}, stride_first=False, add_seblock=False)[source]¶ A building block for ResNets.
in –> Bottleneck with residual_conv –> Bottleneck * (n_layer  1) –> out
 Parameters
n_layer (int) – The number of layers used in the building block.
in_channels (int) – The number of channels of the input array.
mid_channels (int) – The number of channels of intermediate arrays.
out_channels (int) – The number of channels of the output array.
stride (int or tuple of ints) – Stride of filter application.
dilate (int or tuple of ints) – Dilation factor of filter applications.
dilate=d
anddilate=(d, d)
are equivalent.groups (int) – The number of groups to use grouped convolution in the second layer of each bottleneck. The default is one, where grouped convolution is not used.
initialW (callable) – Initial weight value used in the convolutional layers.
bn_kwargs (dict) – Keyword arguments passed to initialize
chainer.links.BatchNormalization
.stride_first (bool) – This determines the behavior of the bottleneck with a shortcut. If
True
, apply strided convolution with the first convolution layer. Otherwise, apply strided convolution with the second convolution layer.add_seblock (bool) – If
True
, apply a squeezeandexcitation block to each residual block.