This is an article about setting up a new computer with the software needed to do Machine Learning on it. We’re going to use Ubuntu 18.04 LTS. If you plan to use Windows on this machine as well, you’ll need to set up dual booting.
Install Ubuntu 18.04 LTS by downloading the image from Ubuntu’s website and imaging it to a USB drive.
There are tutorials from Ubuntu to install Ubuntu from Windows, Mac and Ubuntu I like to use Rufus for imaging if using a Windows machine. Boot up the computer with the USB drive and follow the installation instructions. You may need to set the BIOS up to boot from the USB drive. Make sure your computer is connected to the Internet before starting the installation and it will fetch and install any updates while installing. If your computer was not connected to the internet during installation be sure to run the following commands once it is connected:
sudo apt update sudo apt upgrade
Ubuntu is a distribution of Linux maintained by Canonical. It is free and open-source and fairly user friendly with lots of community support available on the Internet.
I recommend having a ssh server set up to log into your machine. This will be especially useful if you plan on having the computer be headless (no monitor attached).
sudo apt update sudo apt install openssh-server cd /etc/ssh sudo chmod 777 sshd_config
Install the proprietary NVIDIA drivers as well as CUDA and CUDNN to get the full capability of your NVidia GPUs.
You can go to the official NVIDIA website and find which version of the display driver you should use. You can download the drivers from the website or you can install from the terminal with the following command:
sudo apt-get install nvidia-<version number>
Then reboot and ensure the drivers installed by typing:
If you’re using the GUI you can also go to Additional Drivers and select the correct driver for you GPU.
You can go to the CUDA Toolkit website and get the commands for the latest version. For 10.2 on Ubuntu 18.04 use the following commands:
wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run sudo sh cuda_10.2.89_440.33.01_linux.run
Go to the NVIDIA cuDNN home page and sign in with your account or create a new one if you don't have one yet.
Download CUDNN 7.x for CUDA 10.2. Extract the content, this will create a cuda directory, e.g. in ~/Downloads/cuda. After extracting copy the content to the CUDA folder, as follows:
sudo rsync -rl cuda/ /usr/local/cuda
We’re going to install Python virtualenv to enable creating isolated Python environments. This will help with dependency management.
- First make sure you have all the prerequiestes:
sudo apt install python-dev python3-dev python-pip virtualenv sudo pip install virtualenv virtualenvwrapper
Then add the following to your bashrc:
# virtualenv and virtualenvwrapper export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
- Create a new virtual environment named 'virtenv' and specify the python version you like to use on it.
virtualenv -p python3.5 virtenv
- Activate the virtual environment
- You can deactivate the virtenv by typing
Make sure you are in your virtual environment and install the following with pip. Pip is a Python package manager and makes installing software very easy.
pip install numpy pip install scipy pip install pandas pip install matplotlib
Check the installed packages in the virtual environment using:
pip list --format=columns
Let's now install some of the more popular Machine Learning packages.
OpenCV 3.2.0 can be installed from the Ubuntu 18.04 official repository.
sudo apt install python3-opencv
pip install scikit-learn
pip install --upgrade tensorflow-gpu
pip install keras
Now it is time to setup the python environment for PyTorch development.
mkvirtualenv pytorch -p python3 --system-site-packages
Switch to the pytorch virtual environment and then install the packages:
pip install torch torchvision
Hopefully this guide was useful in getting your Machine Learning Box with Ubuntu set up. If you run into trouble be sure to ask the Ubuntu community for help, they are usually a friendly group and more than happy to help.