Creating Artificial Intelligence development environment.

Justine Peterson Mahinyila
3 min readJun 2, 2019

--

Today i just made my first hands on the world of Artificial Intelligence through a scholarship called secure and private AI scholarship challenge offered by Facebook and Udacity.

Secure and private AI scholarship challenge

The first task is to create the working environment on my Ubuntu machine, i created it and i decided to make a work through for anyone out there who might be struggling to make it happen.

Step1: Python installation

You must have python installed on your machine (Python 3.6 or greater version is recommended).To check this run the command

python --version Output
Python 3.7.3

If Python is not installed run this command

sudo apt install python

Or head to the official python website for more instructions

Step:2 Install anaconda package manager

In order to install Pytorch you need a package manager, here were are going to install anaconda package manager.

  1. First head to the Anaconda.com and then click the dowloads button at the top nviagtion menu and then download the linux package then scroll and download the appropriate linux package.Or click this link to go directly to the anaconda installer package and click the download button per your package. Enter the following to install Anaconda for Python 3.7:
bash ~/Downloads/Anaconda3–2019.03-Linux-x86_64.sh

OR Enter the following to install Anaconda for Python 2.7:

bash ~/Downloads/Anaconda2–2019.03-Linux-x86_64.sh

If you did not download to your Downloads directory, replace ~/Downloads/ with the path to the file you downloaded

2.The installer prompts “In order to continue the installation process, please review the license agreement.” Click Enter to view license terms.Scroll to the bottom of the license terms and enter “Yes” to agree.

3.The installer prompts you to click Enter to accept the default install location, CTRL-C to cancel the installation, or specify an alternate installation directory. If you accept the default install location, the installer displays “PREFIX=/home/<user>/anaconda<2 or 3>” and continues the installation. It may take a few minutes to complete. It is recommend you accept the default install location. Do not choose the path as /usr for the Anaconda installation.

4.The installer prompts “Do you wish the installer to initialize Anaconda3 by running conda init?” respond “yes”.
Note If you enter “no”, then conda will not modify your shell scripts at all. In order to initialize after the installation process is done, first runsource <path to conda>/bin/activate and then run conda init. See FAQ.

The installer finishes and displays “Thank you for installing Anaconda<2 or 3>!”

Close and open your terminal window for the installation to take effect, or you can enter the command source ~/.bashrc.

To control whether or not each shell session has the base environment activated or not, run conda config --setauto_activate_base False or True. To run conda from anywhere without having the base environment activated by default, use conda config --set auto_activate_base False. This only works if you have run conda init first.

After your install is complete, verify it by opening Anaconda Navigator, a program that is included with Anaconda: Open a terminal window and type anaconda-navigator. If Navigator opens, you have successfully installed Anaconda.

Step3: Install Pytorch
There are two way to install Pytorch
1.If you have a system capable of using CUDA use the following command

conda install pytorch torchvision cudatoolkit=9.0 -c pytorch

To install PyTorch via Anaconda, and do not have a CUDA-capable system or do not require CUDA, use the following command

conda install pytorch-cpu torchvision-cpu -c pytorch

Finally:

To ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

The output should be something similar to:

tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])

Additionally, to check if your GPU driver and CUDA is enabled and accessible by PyTorch, run the following commands to return whether or not the CUDA driver is enabled:

import torch
torch.cuda.is_available()

--

--

Justine Peterson Mahinyila
Justine Peterson Mahinyila

Written by Justine Peterson Mahinyila

My mission is to improve people’s lives and solve problems using technology in Africa

No responses yet