TorchVision

torchvision

The official PyTorch vision library: datasets, pretrained models and transforms for images, masks and boxes.

ActiveBeginnerv0.29.2BSDComputer Vision & Image Processing

Official documentationTry the examples

Basic information

NameTorchVision
Full nametorchvision
CategoryComputer Vision & Image Processing
DeveloperThe PyTorch team
Release yearNot specified
Official websitegithub.com/pytorch/vision
GitHub repositorypytorch/vision
Official documentationNot specified
Package on PyPItorchvision
LicenseBSD (PyPI license)
Project statusActive Had a release in the last 12 months
Latest version28 October 2026 (version 0.29.2)
Programming languagePython, C++
Operating systemsNot specified
Required Python version!=3.14.1,>=3.10
Difficulty levelBeginner

Data last checked: 21 November 2026 — source: PyPI JSON API (2026-11-21)

Overview

TorchVision provides datasets such as CIFAR and ImageNet (loading interfaces), classification, detection and segmentation models with pretrained weights (ResNet, ViT, Faster R-CNN, Mask R-CNN and others), and v2 transforms that support boxes and masks.

Its version must match the installed PyTorch version; see the compatibility table in the official repository.

When to choose it? Choose it with PyTorch for transfer learning and standard models and transforms.

Uses

Main uses

  • Loading standard datasets
  • Loading standard datasets
  • Pretrained models for transfer learning
  • Pretrained models for transfer learning
  • Image transforms and augmentation
  • Image transforms and augmentation

Scientific fields

  • Computer vision
  • Computer vision
  • Medical imaging
  • Medical imaging

Suitable project types

  • Transfer learning for image classification
  • Transfer learning for image classification

Research applications

  • Standard baselines with ImageNet weights
  • Standard baselines with ImageNet weights

Image classificationObject detectionImage segmentationData augmentation

Technical features

A feature is shown as "Supported" only if it is documented in the library's official documentation; anything we have not verified is shown as "Not specified".

CPU supportSupported
GPU supportSupported
CUDA compatibilitySupported
Distributed training or computingNot applicable
Automatic differentiation (Autodiff)SupportedThrough PyTorch.
Model deploymentSupported
Pre-trained modelsSupported
Supported data typesPyTorch tensors and PIL images
Integration with other librariesPyTorch, Pillow, timm
Flexibility (editorial estimate)Medium
Performance (editorial estimate)High
Community (editorial estimate)Huge
Documentation quality (editorial estimate)Official documentation

Installation and running

Shell
pip install torchvision

Compatibility: Python !=3.14.1,>=3.10 — according to the package data on PyPI, checked on 21 November 2026

Compatibility: Python !=3.14.1,>=3.10 — according to the package data on PyPI, checked on 21 November 2026

Installing inside a virtual environment (venv or conda) is recommended. If you need compatibility with a specific CUDA version or operating system, refer to the official documentation, because this information changes with every release.

Code examples

Examples marked "Run and tested" were actually run, with their output, test date and library versions recorded; the others need a GPU or model downloads, so they were not run in the test environment.

BeginnerImage transforms and a ResNet model from torchvisionRun and tested

Goal: Preparing an image with the standard transforms and passing it to ResNet-18.

Python — example.py
import numpy as np, torch
from PIL import Image
from torchvision import models
from torchvision.transforms import v2

img = Image.fromarray((np.random.default_rng(0).random((300, 400, 3)) * 255).astype("uint8"))
tf = v2.Compose([v2.ToImage(), v2.Resize(256), v2.CenterCrop(224),
                 v2.ToDtype(torch.float32, scale=True),
                 v2.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
x = tf(img).unsqueeze(0)
model = models.resnet18(weights=None, num_classes=4).eval()
with torch.no_grad():
    out = model(x)
print("Input shape:", tuple(x.shape))
print("Output shape:", tuple(out.shape))
print("Number of parameters (millions):", round(sum(p.numel() for p in model.parameters()) / 1e6, 2))

Code explanation

We create a synthetic PIL image and apply v2 transforms (resizing, cropping, conversion to a tensor, normalisation). We use weights=None because downloading pretrained weights needs a connection; in your project use ResNet18_Weights.DEFAULT for transfer learning.

Requirements

Shell
pip install torch torchvision pillow

How to run

Save the code in a file example.py then run it:

Shell
python example.py

Output recorded during testing

Input shape: (1, 3, 224, 224)
Output shape: (1, 4)
Number of parameters (millions): 11.18

This example was actually run and tested on 21 November 2026 on a CPU — torch 2.15.0, torchvision 0.29.2, pillow 13.0.0, python 3.13.18

Example page

All TorchVision examples in the Code Explorer

Pros

  • Official and integrated with PyTorch
  • Ready pretrained models

Limitations

  • A smaller range of models than timm
  • The version must match PyTorch

References and verification

  • Package page on PyPI (source of the version, licence and release date) Checked directly

    https://pypi.org/project/torchvision/

    Checked on: 21 November 2026 — version checked: 0.29.2 — reviewed by: the DLArabic team

  • Official website A link the package officially declares on PyPI

    https://github.com/pytorch/vision

    Checked on: 21 November 2026 — reviewed by: the DLArabic team

  • Official repository A link the package officially declares on PyPI

    https://github.com/pytorch/vision

    Checked on: 21 November 2026 — reviewed by: the DLArabic team

  • Package page on PyPI (source of the version, licence and release date) Checked directly

    https://pypi.org/project/torchvision/

    Checked on: 21 November 2026 — version checked: 0.29.2 — reviewed by: the DLArabic team

  • Official website A link the package officially declares on PyPI

    https://github.com/pytorch/vision

    Checked on: 21 November 2026 — reviewed by: the DLArabic team

  • Official repository A link the package officially declares on PyPI

    https://github.com/pytorch/vision

    Checked on: 21 November 2026 — reviewed by: the DLArabic team

History of verified versions

VersionRelease dateChecked on
0.29.228 October 202621 November 2026

Page information last reviewed: 21 November 2026. The description was written originally for the encyclopedia and is not copied from the official websites.

Report information that needs updating