Home Machine Learning Tutorial
Post
Cancel

Machine Learning Tutorial

In this blog, I would like to introduce how to start your machine learning environment on ubuntu equipped with GPUs . The used tools includes:

  • Miniconda: Independent Python Environment.
  • Machine Learning Framework: Pytorch/Tensorflow.

I should point out that the CUDA and CuDNN are required to install before following the tutorial. You can check the availability of the packages based on the following command.

1
nvcc --version # check the CUDA version

The availability of GPUs can be listed by the command: nvidia-smi.

1. Miniconda

Miniconda is a tool to build a specific python environment for your specific project. The python package installed in the environment will not impact others. Besides, if different versions of the python package are needed in the same machine, miniconda will make it compatible. If we have completed the project and want to delete the python environment, it is also pretty convenient to remove the whole environment.

1.1 Install Miniconda

Different versions of Miniconda are available in the link.

1
2
3
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh # install the miniconda installation script
chmod +x Miniconda3-latest-Linux-x86_64.sh # set access
./Miniconda3-latest-Linux-x86_64.sh # run the package

1.2 Basic Usage

1
2
3
4
5
conda create --name <environment name> python=3 # create a environment with python3
conda activate <environment name> # activate the environment
conda deactivate # deactivate the environment
conda info --envs # list all available environments
conda remove -n <environment name> # remove an environment

When a miniconda environment is activated, (environment name)will be added before each command line of the terminal.

2. Machine Learning Framework

In the section, two main machine learning frameworks which are Pytorch and Tensorflow will be introduced. I will discuss how to install them under the miniconda environment.

2.1 Pytorch

The suitable version of pytorch we want to use is based on both the requirement and the supportive packages’ version. The process to install it is described pretty straightforward on its homepage.

Basically, we can use pip install torchvision torch to install the newest version.

We can check the availability of GPUs on pytorch by the following codes.

1
2
import torch # import pytorch
torch.cuda.is_available() # check the available GPUs' number for pytorch

2.2 Tensorflow

Installing tensorflow can use the similar command by pip install tensorflow-gpu.

GPUs’ availability for tensorflow can be checked by the following way.

1
2
import tensorflow as tf
tf.test.is_gpu_available(cuda_only=False,min_cuda_compute_capability=None)

3. Run Models

After all the steps above, we can clone some models from Github or build personal models by Tensorflow and Pytorch. Some examples are available in tensorflow and pytorch website.

This post is licensed under CC BY 4.0 by the author.

Tricks Summary 2020

Exploit Command Downloading Methods from Google Drive