Why Docker is the best platform to use Tensorflow with a GPU. Docker is the best platform to easily install Tensorflow with a GPU. This tutorial aims demonstrate this and test it on a real-time object recognition application.
Docker is a tool which allows us to pull predefined images. The image we will pull contains TensorFlow and nvidia tools as well as OpenCV. The idea is to package all the necessary tools for image processing. With that, we want to be able to run anyimage processing algorithm within minutes.
First of all, we need to install Docker.
> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - > sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > sudo apt-get update > apt-cache policy docker-ce > sudo apt-get install -y docker-ce > sudo systemctl status docker
After that, we will need to install nvidia-docker if we want to use GPU:
> wget https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb
> sudo dpkg -i nvidia-docker*.deb
At some point, this installation may fail if nvidia-modprobe is not installed, you can try to run (GPU only):
> sudo apt-get install nvidia-modprobe > sudo nvidia-docker-plugin &
Eventually, you can run this command to test your installation. Hopefully, you will get the following output (GPU only):
> sudo nvidia-docker run --rm nvidia/cuda nvidia-smi
!(https://images.ctfassets.net/be04ylp8y0qc/5gFseyqmEDdawhGL9EbFr2/67eb9bd8f500d3956877ec06e68475fa/1_lZl- -DrLap91AzyKvG9g1w.png?fm=webp "")
You probably are familiar with Jupyter Notebook. Jupyter Notebook documents are both human-readable documents containing the analysis description and the results(figures, tables, etc..) as well as executable documents which can be run to perform data analysis. Jupyter Notebook can also run distributed algorithms with GPU.
To run a jupyter notebook with TensorFlow powered by GPU and OpenCv, launch:
> sudo nvidia-docker run --rm --name tf1 -p 8888:8888 -p 6006:6006 redaboumahdi/image_processing:gpu jupyter notebook --allow-root
If you just want to run a jupyter notebook with TensorFlow powered by CPU and OpenCV, you can run the following command:
> sudo docker run --rm --name tf1 -p 8888:8888 -p 6006:6006 redaboumahdi/image_processing:cpu jupyter notebook --allow-root
You will get the following result out of your terminal. Then you can navigate to your localhost and use the port 8888, for me, the link looks like this: http://localhost:8888/
You will need to paste your token to identify and access your jupyter notebooks:
And eventually, you will get the following result. You can therefore test your installation by running the jupyter notebooks.
The first link is a hello TensorFlow notebook to get more familiar with this tool. ]TensorFlow is an open-source software library for dataflow programming across a range of tasks. It is principally used to build deep neural networks. The third link gives an example of using TensorFlow to build a simple fully connected neural network. You can find here a TensorFlow implementation of a convolutionnal neural network. I highly recommand using GPU to train CNN / RNN / LSTM networks.
Now it is time to test our configuration and spend some time with ourmachine learning algorithms. The following code helps us track objects over frames with our webcam. It is a sample of code taken from the internet, you can find the github repository at the end of the article.
First of all, we need to open the access to the xserver to our docker image. There are different ways of doing so. The first one opens an access to your xserver to anyone. Other methods are described in the links at the end of the article.
> xhost +local:root
Then we will bash to our Docker image using this command:
> sudo docker run -p 8888:8888 --device /dev/video0 --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -it image_processing bash
We will need to clone the github repository, which is a real-time object detector:
> git clone https://github.com/datitran/object_detector_app.git && cd object_detector_app/
Finally, you can launch the python code:
> python object_detection_app.py
The code that we are using uses OpenCV. It is know as one of the most used libraries for image processing and available for C++ as well as Python.
You should see the following output, OpenCV will open your webcam and render a video. OpenCV will also find any object in the frame and print the label of the predicted object.
I showed how one can use Docker to get your computer ready for image processing. This image contains OpenCV and TensorFlow with either GPU or CPU. We tested our installation through a real-time object detector. I hope it convinced you that most of what you need to process images is contained in this Docker image. Thank you for following my tutorial. Please don’t hesitate to send me any feedback!
This entry-level guide will tell you why and how to Dockerize your WordPress projects.
We can get a list of all containers in docker using `docker container list` or `docker ps` commands.
Docker basics , what is docker? What is a container?
Setting up NodeJS with MongoDB using Docker and Docker Compose - Learn about Docker and how to spin up a Docker orchestration for your development environment so, that way, you don't have to install MongoDB, you can just r...
In this Docker tutorial for beginners provides an Introduction on Working with Docker Images, Docker Search, Docker List, Docker Push, Docker Pull. We will learn How to Write Dockerfiles, Working with the Docker Toolbox, How to Work with the Docker Machine, How to Use Docker Compose to fire up multiple containers, How to Work with Docker Kinematic, Push images to Docker Hub, Pull images from a Docker Registery, Push stacks of servers to Docker Hub