Shortcuts

resnet18

torchvision.models.resnet18(*, weights: Optional[ResNet18_Weights] = None, progress: bool = True, **kwargs: Any) ResNet[source]

ResNet-18 from Deep Residual Learning for Image Recognition.

Parameters:
  • weights (ResNet18_Weights, optional) – The pretrained weights to use. See ResNet18_Weights below for more details, and possible values. By default, no pre-trained weights are used.

  • progress (bool, optional) – If True, displays a progress bar of the download to stderr. Default is True.

  • **kwargs – parameters passed to the torchvision.models.resnet.ResNet base class. Please refer to the source code for more details about this class.

class torchvision.models.ResNet18_Weights(value)[source]

The model builder above accepts the following values as the weights parameter. ResNet18_Weights.DEFAULT is equivalent to ResNet18_Weights.IMAGENET1K_V1. You can also use strings, e.g. weights='DEFAULT' or weights='IMAGENET1K_V1'.

ResNet18_Weights.IMAGENET1K_V1:

These weights reproduce closely the results of the paper using a simple training recipe. Also available as ResNet18_Weights.DEFAULT.

acc@1 (on ImageNet-1K)

69.758

acc@5 (on ImageNet-1K)

89.078

min_size

height=1, width=1

categories

tench, goldfish, great white shark, … (997 omitted)

num_params

11689512

recipe

link

The inference transforms are available at ResNet18_Weights.IMAGENET1K_V1.transforms and perform the following preprocessing operations: Accepts PIL.Image, batched (B, C, H, W) and single (C, H, W) image torch.Tensor objects. The images are resized to resize_size=[256] using interpolation=InterpolationMode.BILINEAR, followed by a central crop of crop_size=[224]. Finally the values are first rescaled to [0.0, 1.0] and then normalized using mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225].

Examples using resnet18:

Tensor transforms and JIT

Tensor transforms and JIT

Tensor transforms and JIT

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources