• Stars
    star
    902
  • Rank 50,637 (Top 1.0 %)
  • Language
    Dockerfile
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Docker image for PyTorch

PyTorch Docker image

Docker image version Docker image pulls Docker image size

Ubuntu + PyTorch + CUDA (optional)

Requirements

In order to use this image you must have Docker Engine installed. Instructions for setting up Docker Engine are available on the Docker website.

CUDA requirements

If you have a CUDA-compatible NVIDIA graphics card, you can use a CUDA-enabled version of the PyTorch image to enable hardware acceleration. I have only tested this in Ubuntu Linux.

Firstly, ensure that you install the appropriate NVIDIA drivers. On Ubuntu, I've found that the easiest way of ensuring that you have the right version of the drivers set up is by installing a version of CUDA at least as new as the image you intend to use via the official NVIDIA CUDA download page. As an example, if you intend on using the cuda-10.1 image then setting up CUDA 10.1 or CUDA 10.2 should ensure that you have the correct graphics drivers.

You will also need to install the NVIDIA Container Toolkit to enable GPU device access within Docker containers. This can be found at NVIDIA/nvidia-docker.

Prebuilt images

Prebuilt images are available on Docker Hub under the name anibali/pytorch.

For example, you can pull an image with PyTorch 2.0.0 and CUDA 11.8 using:

$ docker pull anibali/pytorch:2.0.0-cuda11.8

Usage

Running PyTorch scripts

It is possible to run PyTorch programs inside a container using the python3 command. For example, if you are within a directory containing some PyTorch project with entrypoint main.py, you could run it with the following command:

docker run --rm -it --init \
  --gpus=all \
  --ipc=host \
  --user="$(id -u):$(id -g)" \
  --volume="$PWD:/app" \
  anibali/pytorch python3 main.py

Here's a description of the Docker command-line options shown above:

  • --gpus=all: Required if using CUDA, optional otherwise. Passes the graphics cards from the host to the container. You can also more precisely control which graphics cards are exposed using this option (see documentation at https://github.com/NVIDIA/nvidia-docker).
  • --ipc=host: Required if using multiprocessing, as explained at https://github.com/pytorch/pytorch#docker-image.
  • --user="$(id -u):$(id -g)": Sets the user inside the container to match your user and group ID. Optional, but is useful for writing files with correct ownership.
  • --volume="$PWD:/app": Mounts the current working directory into the container. The default working directory inside the container is /app. Optional.

Running graphical applications

If you are running on a Linux host, you can get code running inside the Docker container to display graphics using the host X server (this allows you to use OpenCV's imshow, for example). Here we describe a quick-and-dirty (but INSECURE) way of doing this. For a more comprehensive guide on GUIs and Docker check out http://wiki.ros.org/docker/Tutorials/GUI.

On the host run:

sudo xhost +local:root

You can revoke these access permissions later with sudo xhost -local:root. Now when you run a container make sure you add the options -e "DISPLAY" and --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw". This will provide the container with your X11 socket for communication and your display ID. Here's an example:

docker run --rm -it --init \
  --gpus=all \
  -e "DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
  anibali/pytorch python3 -c "import tkinter; tkinter.Tk().mainloop()"

Deriving your own images

The recommended way of adding additional dependencies to an image is to create your own Dockerfile using one of the PyTorch images from this project as a base.

For example, let's say that you require OpenCV and wish to work with PyTorch 2.0.0. You can create your own Dockerfile using anibali/pytorch:2.0.0-cuda11.8-ubuntu22.04 as the base image and install OpenCV using additional build steps:

FROM anibali/pytorch:2.0.0-cuda11.8-ubuntu22.04

# Set up time zone.
ENV TZ=UTC
RUN sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime

# Install system libraries required by OpenCV.
RUN sudo apt-get update \
 && sudo apt-get install -y libgl1-mesa-glx libgtk2.0-0 libsm6 libxext6 \
 && sudo rm -rf /var/lib/apt/lists/*

# Install OpenCV from PyPI.
RUN pip install opencv-python==4.5.1.48

Development and contributing

The Dockerfiles in the dockerfiles/ directory are automatically generated by the manager.py script using details in images.yml and the templates in templates/.

Here's an example workflow illustrating how to create a new Dockerfile.

  1. (Optional) Create a new template file in templates/ if none of the existing ones are appropriate.
  2. Create a new entry in images.yml (see the existing entries for examples).
  3. Generate the Dockerfile by running python manager.py. A new directory containing the Dockerfile will be created in dockerfiles/.
  4. Build the generated Dockerfile and test that it works. You can stop here if you are creating an image for your own use.
  5. (Optional) Submit a PR if you think that your new image might be useful for others, and it will be considered for publication.

More Repositories

1

h36m-fetch

Human 3.6M 3D human pose dataset fetcher
Python
329
star
2

dsntnn

PyTorch implementation of DSNT
Python
290
star
3

margipose

3D monocular human pose estimation
Python
96
star
4

pywebp

Python bindings for WebP
Python
67
star
5

eval-mpii-pose

Evaluation code for the MPII human pose dataset
MATLAB
62
star
6

aspset-510

A large-scale video dataset for the training and evaluation of 3D human pose estimation models
Python
38
star
7

docker-torch

A Docker image for Lua Torch
Shell
26
star
8

coal

A low-level language which may be embedded in Ruby code
Ruby
23
star
9

lua-ffmpeg-ffi

LuaJIT FFI bindings to FFmpeg libraries
Lua
20
star
10

infogan

An unofficial Torch implementation of InfoGAN
Lua
19
star
11

tvl

Torch video loading library with support for GPU decoding
C++
18
star
12

dsnt-pose2d

2D human pose estimation with DSNT
Python
14
star
13

lidc-idri-preprocessing

Code for preprocessing the LIDC-IDRI lung cancer screening CT scan dataset
Lua
13
star
14

segformer

An unofficial PyTorch implementation of SegFormer
Python
9
star
15

etcd.lua

Lua etcd client
Lua
8
star
16

pose3d-utils

3D pose utilities for PyTorch
Python
7
star
17

pybraw

Python bindings for the Blackmagic RAW SDK.
C++
7
star
18

tohiccup

Web app for converting HTML to Hiccup
Clojure
7
star
19

torchvid

Utilities for loading videos into Torch using FFmpeg libraries
C
6
star
20

posekit

Python
5
star
21

trajic

A GPS trajectory compression system
C++
5
star
22

ruby-ogg

Ruby love for the Ogg container format
Ruby
5
star
23

wgan-cifar10

Unofficial implementation of WGAN in PyTorch for CIFAR-10
Python
5
star
24

dlds

Easily install deep learning datasets
Lua
2
star
25

libjit-ffi

Ruby bindings for LibJIT via FFI
Ruby
2
star
26

toneforge

A GTK application for generating tones
Ruby
2
star
27

burke

Helper for creating nice, clean Rake files
Ruby
2
star
28

siren

Lua
1
star
29

showoff

JavaScript
1
star
30

dismaldenizen.github.com

Home page for dismaldenizen
1
star
31

aiden.nibali.org

Source for my personal website and blog
HTML
1
star
32

little_birdy

A collection of useful Ruby helpers
Ruby
1
star
33

docker-npm-register

1
star
34

ipynb-docker

Shell
1
star
35

rat_trace_avr

C
1
star
36

digitemp-exporter

Prometheus metrics exporter for DigiTemp temperature sensors
Python
1
star
37

dot-files

My configuration files for various applications
Shell
1
star
38

lua-notebook

JavaScript
1
star
39

docker-opensim

A Docker image for OpenSim
Dockerfile
1
star
40

dockerfiles

Lua
1
star