May 2
Installing Tensorflow(GPU), OpenCV and dlib on Ubuntu 18.04 Bionic Beaver
Image source: https://www.tensorflow.org/
For those who are ready for machine learning and computer vision with the updated versions of OpenCV, dlib, Tensorflow (GPU) on the Bionic Beaver.
Install synaptic and atom from Ubuntu’s package manager
[code language=”bash”]
sudo ubuntu-drivers autoinstall
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
[/code]
search and install nvidia-390 from synaptic
Download CUDA 9.0 (It has to be 9.0 for Tensorflow 1.8):
And Download cuDNN v7.1.3 for CUDA 9.0:
https://developer.nvidia.com/rdp/cudnn-download
[code language=”bash”]
sudo chmod +x cuda_9.0.176_384.81_linux.run
sudo chmod +x cuda_9.0.176.1_linux.run
sudo chmod +x cuda_9.0.176.2_linux.run
sudo ./cuda_9.0.176_384.81_linux.run –override
sudo ./cuda_9.0.176.1_linux.run
sudo ./cuda_9.0.176.2_linux.run
[/code]
DO NOT INSTALL THE DRIVER AND SAMPLES IN THIS PART! Ignore the fact that they give you a warning for the driver not being installed. This is because the installer cannot detect the installed driver in your system, which we installed earlier through synaptic.
[code language=”bash”]
sudo apt-get install cuda-9
sudo apt-get upgrade
tar -zxvf cudnn-9.0-linux-x64-v7.1.tgz
sudo cp -P cuda/lib64/* /usr/local/cuda-9.0/lib64/
sudo cp cuda/include/* /usr/local/cuda-9.0/include/
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h
sudo apt-get install libcupti-dev
sudo atom ~/.bashrc
[/code]
And add these lines:
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
[code language=”bash”]
source ~/.bashrc
sudo apt-get update
sudo apt-get install build-essential cmake libopenblas-dev liblapack-dev libx11-dev libgtk-3-dev python python-dev python-pip python3 python3-dev python3-pip
[/code]
Download and install Anaconda Python 3.6 (I use 3.6 universally and 2.7 for scientific computations)
Create environment using an environment name (envname)
[code language=”bash”]
conda create -n envname python=2.7
source activate envname
pip install numpy pillow lxml jupyter matplotlib dlib protobuf
sudo apt -y install python-opencv
conda install -c conda-forge opencv
sudo snap install protobuf –classic
pip install –upgrade tensorflow-gpu
[/code]
To KILL process and clear memory of GPU:
[code language=”bash”]
nvidia-smi
[/code]
and kill the process causing unwanted memory usage
[code language=”bash”]
sudo kill -20483 PID.
[/code]