Shortcuts

PyTorch Examples

This pages lists various PyTorch examples that you can use to learn and experiment with PyTorch.

Image Classification using Vision Transformer

This example shows how to train a Vision Transformer from scratch on the CIFAR10 database.

GO TO EXAMPLE

Image Classification Using ConvNets

This example demonstrates how to run image classification with Convolutional Neural Networks ConvNets on the MNIST database.

GO TO EXAMPLE

Measuring Similarity using Siamese Network

This example demonstrates how to measure similarity between two images using Siamese network on the MNIST database.

GO TO EXAMPLE

Word-level Language Modeling using RNN and Transformer

This example demonstrates how to train a multi-layer recurrent neural network (RNN), such as Elman, GRU, or LSTM, or Transformer on a language modeling task by using the Wikitext-2 dataset.

GO TO EXAMPLE

Training ImageNet Classifiers

This example demonstrates how you can train some of the most popular model architectures, including ResNet, AlexNet, and VGG on the ImageNet dataset.

GO TO EXAMPLE

Generative Adversarial Networks (DCGAN)

Variational Auto-Encoders

This example implements the Auto-Encoding Variational Bayes paper with ReLUs and the Adam optimizer.

GO TO EXAMPLE

Super-resolution Using an Efficient Sub-Pixel CNN

This example demonstrates how to use the sub-pixel convolution layer described in Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network paper. This example trains a super-resolution network on the BSD300 dataset.

GO TO EXAMPLE

HOGWILD! Training of Shared ConvNets

HOGWILD! is a scheme that allows Stochastic Gradient Descent (SGD) parallelization without memory locking. This example demonstrates how to perform HOGWILD! training of shared ConvNets on MNIST.

GO TO EXAMPLE

Training a CartPole to balance in OpenAI Gym with actor-critic

This reinforcement learning tutorial demonstrates how to train a CartPole to balance in the OpenAI Gym toolkit by using the Actor-Critic method.

GO TO EXAMPLE

Time Sequence Prediction

This beginner example demonstrates how to use LSTMCell to learn sine wave signals to predict the signal values in the future.

GO TO EXAMPLE

Implement the Neural Style Transfer algorithm on images

This tutorial demonstrates how you can use PyTorch’s implementation of the Neural Style Transfer (NST) algorithm on images.

GO TO EXAMPLE

PyTorch Module Transformations using fx

This set of examples demonstrates the torch.fx toolkit. For more information about torch.fx, see torch.fx Overview.

GO TO EXAMPLE

Distributed PyTorch

This set of examples demonstrates Distributed Data Parallel (DDP) and Distributed RPC framework. Includes the code used in the DDP tutorial series.

GO TO EXAMPLES

C++ Frontend

The PyTorch C++ frontend is a C++14 library for CPU and GPU tensor computation. This set of examples includes a linear regression, autograd, image recognition (MNIST), and other useful examples using PyTorch C++ frontend.

GO TO EXAMPLES

Image Classification Using Forward-Forward Algorithm

This example implements the paper The Forward-Forward Algorithm: Some Preliminary Investigations by Geoffrey Hinton. on the MNIST database. It is an introductory example to the Forward-Forward algorithm.

GO TO EXAMPLE

Graph Convolutional Network

This example implements the Semi-Supervised Classification with Graph Convolutional Networks paper on the CORA database.

GO TO EXAMPLE

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