composer.models.tasks.classification#

A convenience class that creates a ComposerModel for classification tasks from a vanilla PyTorch model.

ComposerClassifier requires batches in the form: (input, target) and includes a basic classification training loop with soft_cross_entropy() loss and accuracy logging.

Classes

ComposerClassifier

A convenience class that creates a ComposerModel for classification tasks from a vanilla PyTorch model.

class composer.models.tasks.classification.ComposerClassifier(module, loss_name='soft_cross_entropy')[source]#

Bases: composer.models.base.ComposerModel

A convenience class that creates a ComposerModel for classification tasks from a vanilla PyTorch model. ComposerClassifier requires batches in the form: (input, target) and includes a basic classification training loop with soft_cross_entropy() loss and accuracy logging.

Parameters
  • module (Module) โ€“ A PyTorch neural network module.

  • 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'โ€.

Returns

ComposerClassifier โ€“ An instance of ComposerClassifier.

Example:

import torchvision
from composer.models import ComposerClassifier

pytorch_model = torchvision.models.resnet18(pretrained=False)
model = ComposerClassifier(pytorch_model)