• Stars
    star
    3,860
  • Rank 11,370 (Top 0.3 %)
  • Language
    Python
  • Created over 8 years ago
  • Updated about 5 years ago

Reviews

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

Repository Details

An all-in-one Docker image for deep learning. Contains all the popular DL frameworks (TensorFlow, Theano, Torch, Caffe, etc.)

Website β€’ Docs β€’ Forum β€’ Twitter β€’ We're Hiring

FloydHub Logo

All-in-one Docker image for Deep Learning

Here are Dockerfiles to get you up and running with a fully functional deep learning machine. It contains all the popular deep learning frameworks with CPU and GPU support (CUDA and cuDNN included). The CPU version should work on Linux, Windows and OS X. The GPU version will, however, only work on Linux machines. See OS support for details

If you are not familiar with Docker, but would still like an all-in-one solution, start here: What is Docker?. If you know what Docker is, but are wondering why we need one for deep learning, see this

Update: I've built a quick tool, based on dl-docker, to run your DL project on the cloud with zero setup. You can start running your Tensorflow project on AWS in <30seconds using Floyd. See www.floydhub.com. It's free to try out.

Happy to take feature requests/feedback and answer questions - mail me [email protected].

Specs

This is what you get out of the box when you create a container with the provided image/Dockerfile:

Setup

Prerequisites

  1. Install Docker following the installation guide for your platform: https://docs.docker.com/engine/installation/

  2. GPU Version Only: Install Nvidia drivers on your machine either from Nvidia directly or follow the instructions here. Note that you don't have to install CUDA or cuDNN. These are included in the Docker container.

  3. GPU Version Only: Install nvidia-docker: https://github.com/NVIDIA/nvidia-docker, following the instructions here. This will install a replacement for the docker CLI. It takes care of setting up the Nvidia host driver environment inside the Docker containers and a few other things.

Obtaining the Docker image

You have 2 options to obtain the Docker image

Option 1: Download the Docker image from Docker Hub

Docker Hub is a cloud based repository of pre-built images. You can download the image directly from here, which should be much faster than building it locally (a few minutes, based on your internet speed). Here is the automated build page for dl-docker: https://hub.docker.com/r/floydhub/dl-docker/. The image is automatically built based on the Dockerfile in the Github repo.

CPU Version

docker pull floydhub/dl-docker:cpu

GPU Version An automated build for the GPU image is not available currently due to timeout restrictions in Docker's automated build process. I'll look into solving this in the future, but for now you'll have to build the GPU version locally using Option 2 below.

Option 2: Build the Docker image locally

Alternatively, you can build the images locally. Also, since the GPU version is not available in Docker Hub at the moment, you'll have to follow this if you want to GPU version. Note that this will take an hour or two depending on your machine since it compiles a few libraries from scratch.

git clone https://github.com/saiprashanths/dl-docker.git
cd dl-docker

CPU Version

docker build -t floydhub/dl-docker:cpu -f Dockerfile.cpu .

GPU Version

docker build -t floydhub/dl-docker:gpu -f Dockerfile.gpu .

This will build a Docker image named dl-docker and tagged either cpu or gpu depending on the tag your specify. Also note that the appropriate Dockerfile.<architecture> has to be used.

Running the Docker image as a Container

Once we've built the image, we have all the frameworks we need installed in it. We can now spin up one or more containers using this image, and you should be ready to go deeper

CPU Version

docker run -it -p 8888:8888 -p 6006:6006 -v /sharedfolder:/root/sharedfolder floydhub/dl-docker:cpu bash

GPU Version

nvidia-docker run -it -p 8888:8888 -p 6006:6006 -v /sharedfolder:/root/sharedfolder floydhub/dl-docker:gpu bash

Note the use of nvidia-docker rather than just docker

Parameter Explanation
-it This creates an interactive terminal you can use to iteract with your container
-p 8888:8888 -p 6006:6006 This exposes the ports inside the container so they can be accessed from the host. The format is -p <host-port>:<container-port>. The default iPython Notebook runs on port 8888 and Tensorboard on 6006
-v /sharedfolder:/root/sharedfolder/ This shares the folder /sharedfolder on your host machine to /root/sharedfolder/ inside your container. Any data written to this folder by the container will be persistent. You can modify this to anything of the format -v /local/shared/folder:/shared/folder/in/container/. See Docker container persistence
floydhub/dl-docker:cpu This the image that you want to run. The format is image:tag. In our case, we use the image dl-docker and tag gpu or cpu to spin up the appropriate image
bash This provides the default command when the container is started. Even if this was not provided, bash is the default command and just starts a Bash session. You can modify this to be whatever you'd like to be executed when your container starts. For example, you can execute docker run -it -p 8888:8888 -p 6006:6006 floydhub/dl-docker:cpu jupyter notebook. This will execute the command jupyter notebook and starts your Jupyter Notebook for you when the container starts

Some common scenarios

Jupyter Notebooks

The container comes pre-installed with iPython and iTorch Notebooks, and you can use these to work with the deep learning frameworks. If you spin up the docker container with docker-run -p <host-port>:<container-port> (as shown above in the instructions), you will have access to these ports on your host and can access them at http://127.0.0.1:<host-port>. The default iPython notebook uses port 8888 and Tensorboard uses port 6006. Since we expose both these ports when we run the container, we can access them both from the localhost.

However, you still need to start the Notebook inside the container to be able to access it from the host. You can either do this from the container terminal by executing jupyter notebook or you can pass this command in directly while spinning up your container using the docker run -it -p 8888:8888 -p 6006:6006 floydhub/dl-docker:cpu jupyter notebook CLI. The Jupyter Notebook has both Python (for TensorFlow, Caffe, Theano, Keras, Lasagne) and iTorch (for Torch) kernels.

Note: If you are setting the notebook on Windows, you will need to first determine the IP address of your Docker container. This command on the Docker command-line provides the IP address

docker-machine ip default
> <IP-address>

default is the name of the container provided by default to the container you will spin. On obtaining the IP-address, run the docker as per the instructions provided and start the Jupyter notebook as described above. Then accessing http://<IP-address>:<host-port> on your host's browser should show you the notebook.

Data Sharing

See Docker container persistence. Consider this: You have a script that you've written on your host machine. You want to run this in the container and get the output data (say, a trained model) back into your host. The way to do this is using a Shared Volume. By passing in the -v /sharedfolder/:/root/sharedfolder to the CLI, we are sharing the folder between the host and the container, with persistence. You could copy your script into /sharedfolder folder on the host, execute your script from inside the container (located at /root/sharedfolder) and write the results data back to the same folder. This data will be accessible even after you kill the container.

What is Docker?

Docker itself has a great answer to this question.

Docker is based on the idea that one can package code along with its dependencies into a self-contained unit. In this case, we start with a base Ubuntu 14.04 image, a bare minimum OS. When we build our initial Docker image using docker build, we install all the deep learning frameworks and its dependencies on the base, as defined by the Dockerfile. This gives us an image which has all the packages we need installed in it. We can now spin up as many instances of this image as we like, using the docker run command. Each instance is called a container. Each of these containers can be thought of as a fully functional and isolated OS with all the deep learning libraries installed in it.

Why do I need a Docker?

Installing all the deep learning frameworks to coexist and function correctly is an exercise in dependency hell. Unfortunately, given the current state of DL development and research, it is almost impossible to rely on just one framework. This Docker is intended to provide a solution for this use case.

If you would rather install all the frameworks yourself manually, take a look at this guide: Setting up a deep learning machine from scratch

Do I really need an all-in-one container?

No. The provided all-in-one solution is useful if you have dependencies on multiple frameworks (say, load a pre-trained Caffe model, finetune it, convert it to Tensorflow and continue developing there) or if you just want to play around with the various frameworks.

The Docker philosophy is to build a container for each logical task/framework. If we followed this, we should have one container for each of the deep learning frameworks. This minimizes clashes between frameworks and is easier to maintain as things evolve. In fact, if you only intend to use one of the frameworks, or at least use only one framework at a time, follow this approach. You can find Dockerfiles for individual frameworks here:

FAQs

Performance

Running the DL frameworks as Docker containers should have no performance impact during runtime. Spinning up a Docker container itself is very fast and should take only a couple of seconds or less

Docker container persistence

Keep in mind that the changes made inside Docker container are not persistent. Lets say you spun up a Docker container, added and deleted a few files and then kill the container. The next time you spin up a container using the same image, all your previous changes will be lost and you will be presented with a fresh instance of the image. This is great, because if you mess up your container, you can always kill it and start afresh again. It's bad if you don't know/understand this and forget to save your work before killing the container. There are a couple of ways to work around this:

  1. Commit: If you make changes to the image itself (say, install a few new libraries), you can commit the changes and settings into a new image. Note that this will create a new image, which will take a few GBs space on your disk. In your next session, you can create a container from this new image. For details on commit, see Docker's documentaion.

  2. Shared volume: If you don't make changes to the image itself, but only create data (say, train a new Caffe model), then commiting the image each time is an overkill. In this case, it is easier to persist the data changes to a folder on your host OS using shared volumes. Simple put, the way this works is you share a folder from your host into the container. Any changes made to the contents of this folder from inside the container will persist, even after the container is killed. For more details, see Docker's docs on Managing data in containers

How do I update/install new libraries?

You can do one of:

  1. Modify the Dockerfile directly to install new or update your existing libraries. You will need to do a docker build after you do this. If you just want to update to a newer version of the DL framework(s), you can pass them as CLI parameter using the --build-arg tag ([see](-v /sharedfolder:/root/sharedfolder) for details). The framework versions are defined at the top of the Dockerfile. For example, docker build -t floydhub/dl-docker:cpu -f Dockerfile.cpu --build-arg TENSORFLOW_VERSION=0.9.0rc0 .

  2. You can log in to a container and install the frameworks interactively using the terminal. After you've made sure everything looks good, you can commit the new contains and store it as an image

What operating systems are supported?

Docker is supported on all the OSes mentioned here: Install Docker Engine (i.e. different flavors of Linux, Windows and OS X). The CPU version (Dockerfile.cpu) will run on all the above operating systems. However, the GPU version (Dockerfile.gpu) will only run on Linux OS. This is because Docker runs inside a virtual machine on Windows and OS X. Virtual machines don't have direct access to the GPU on the host. Unless PCI passthrough is implemented for these hosts, GPU support isn't available on non-Linux OSes at the moment.

More Repositories

1

dl-setup

Instructions for setting up the software on your deep learning machine
1,980
star
2

imagenet

Pytorch Imagenet Models Example + Transfer Learning (and fine-tuning)
Python
157
star
3

floyd-cli

Command line tool for FloydHub - the fastest way to build, train, and deploy deep learning models
Python
156
star
4

dockerfiles

Deep Learning Dockerfiles
Python
156
star
5

tensorflow-examples

Sample tensorflow code to try on Floyd
Python
72
star
6

tensorflow-notebooks-examples

Tensorflow Notebook Examples and Tutorials
Jupyter Notebook
66
star
7

pix2code-template

Build a neural network to code a basic a HTML and CSS website based on a picture of a design mockup.
Jupyter Notebook
64
star
8

floyd-docs

FloydHub's documentation code. Contributions welcome!
HTML
63
star
9

named-entity-recognition-template

Build a deep learning model for predicting the named entities from text.
Jupyter Notebook
55
star
10

mnist

Pytorch mnist example
Python
46
star
11

examples

FloydHub Examples – A collection of boilerplates and examples of machine learning and deep learning models to build, train, and deploy on FloydHub
37
star
12

colornet-template

Colorizing B&W Photos with Neural Networks
Jupyter Notebook
36
star
13

save-and-resume

Checkpoint tutorial on FloydHub for Pytorch, Keras and Tensorflow.
Jupyter Notebook
36
star
14

dcgan

Porting pytorch dcgan on FloydHub
Python
34
star
15

word-language-model

Pytorch world language model (text generation) for PTB dataset example
Python
34
star
16

textutil-preprocess-cornell-movie-corpus

textutil-preprocess-cornell-movie-corpus
Python
33
star
17

time-sequence-prediction

FloydHub porting of Pytorch time-sequence-prediction example
Python
28
star
18

quick-start

FloydHub quick start project - train TensorFlow model with MNIST dataset
Jupyter Notebook
25
star
19

sentiment-analysis-template

Build a deep learning model for sentiment analysis of IMDB reviews
Jupyter Notebook
24
star
20

language-identification-template

Detect the languages from short pieces of text
Jupyter Notebook
22
star
21

image-classification-template

Build a deep learning model for classifying dog breeds from their images
Jupyter Notebook
16
star
22

object-detection-template

Tensorflow Object Detection API on `Where is Syd?` dataset
Python
14
star
23

fast-neural-style

FloydHub porting of Pytorch fast-neural-style example
Python
14
star
24

hyperparameters-search-examples

Code examples for https://blog.floydhub.com/guide-to-hyperparameters-search-for-deep-learning-models/
Jupyter Notebook
11
star
25

keras-examples

Official Keras example projects on Floyd
11
star
26

quick-start-pytorch

Floyd quickstart project with PyTorch
Jupyter Notebook
9
star
27

gym-retro-template

One-click setup for OpenAI Gym Retro on FloydHub
Jupyter Notebook
9
star
28

regression-template

Build a deep learning model for predicting the price of wine given the description
Jupyter Notebook
9
star
29

regression

Pytorch Linear Regression example
Python
8
star
30

Screenshot-to-code-backup

Additional materials for https://blog.floydhub.com/turning-design-mockups-into-code-with-deep-learning/
HTML
7
star
31

deep-photo-styletransfer

Jupyter Notebook to train photorealistic style transfer
Lua
5
star
32

chatbot-demo

chatbot-demo
JavaScript
3
star
33

automate

For automating FloydHub workflows
Jupyter Notebook
3
star
34

ideas

Content ideas
1
star
35

mnist-demo

Comprehensive MNIST demo
Jupyter Notebook
1
star
36

pytorch-nn-tutorial

PyTorch Tutorial for Workspace: what is torch.nn really?
Jupyter Notebook
1
star
37

floydhub.github.io

Floyd website
CSS
1
star
38

textutil-normalize-text

Simple text normalization for English.
Python
1
star
39

textutil-shuffle-file

Randomly shuffle lines in a text file
Python
1
star