composer.models.composer_resnet(model_name, num_classes=1000, weights=None, pretrained=False, groups=1, width_per_group=64, initializers=None, loss_name='soft_cross_entropy')[source]#

Helper function to create a ComposerClassifier with a torchvision ResNet model.

From Deep Residual Learning for Image Recognition (He et al, 2015).

  • model_name (str) โ€“ Name of the ResNet model instance. Either ["resnet18", "resnet34", "resnet50", "resnet101", "resnet152"].

  • num_classes (int, optional) โ€“ The number of classes. Needed for classification tasks. Default: 1000.

  • weights (str, optional) โ€“ If provided, pretrained weights can be specified, such as with IMAGENET1K_V2. Default: None.

  • pretrained (bool, optional) โ€“ If True, use ImageNet pretrained weights. Default: False. This parameter is deprecated and will soon be removed in favor of weights.

  • groups (int, optional) โ€“ Number of filter groups for the 3x3 convolution layer in bottleneck blocks. Default: 1.

  • width_per_group (int, optional) โ€“ Initial width for each convolution group. Width doubles after each stage. Default: 64.

  • initializers (List[Initializer], optional) โ€“ Initializers for the model. None for no initialization. Default: None.

  • loss_name (str, optional) โ€“ Loss function to use. E.g. โ€˜soft_cross_entropyโ€™ or โ€˜binary_cross_entropy_with_logitsโ€™. Loss function must be in loss. Default: 'soft_cross_entropy'โ€.


ComposerModel โ€“ instance of ComposerClassifier with a torchvision ResNet model.


from composer.models import composer_resnet

model = composer_resnet(model_name='resnet18')  # creates a torchvision resnet18 for image classification