Wednesday, April 29, 2020

How to install tensorflow gpu for Ubuntu 20.04 or Mac OSX

1. Boot into Ubuntu 20.04 or Ubuntu 18.04

2. Download Anaconda3-2020.02-Linux-x86_64.sh from https://repo.anaconda.com/archive/

3. Start installation in Terminal

shell script    Select all
wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh /bin/sh Anaconda3-2020.02-Linux-x86_64.sh # After completion of installation, and accept init exit


4. Start Terminal App again

5. Update Anaconda, create virtual environment and install packages
shell script    Select all
conda config --set auto_activate_base false conda deactivate # Exit conda shell conda update conda conda update anaconda conda update python conda update --all mkdir -p $HOME/Projects cd $HOME/Projects/ conda create --name tf-gpu conda activate tf-gpu # Now in (tf-gpu) shell conda install tensorflow-gpu conda install matplotlib pandas scikit-learn conda install keras


6. Run the examples in how-to-install-tensorflow-with-gpu

or run the TensorFlow2 tutorial
conda activate tf-gpu
git clone https://github.com/lambdal/TensorFlow2-tutorial.git
cd TensorFlow2-tutorial/01-basic-image-classification/
python resnet_cifar.py


7. It is not necessary to have the required GPU hardware in order to install the gpu package, For machine without the required GPU, just first install tensorflow_gpu package and then download and install the tensorflow wheels file here
pip install --upgrade ~/Downloads/tensorflow-2.1.0-cp37-cp37m-linux_x86_64.whl
, in order to optimise for CPU with AVX, AVX2, and FMA or to build from source here -> https://www.tensorflow.org/install/source



Install tensorflow-mkl for Mac OS X


The installation steps are very similar, except
Download and install Anaconda3-2020.02-MacOSX-x86_64.pkg
curl -OL https://repo.anaconda.com/archive/Anaconda3-2020.02-MacOSX-x86_64.pkg
And then follow step 4 to step 6 above. In step 5, additionally, install tensorflow-mkl from anaconda channel. tensorflow-mkl is optimized with Intel® MKL-DNN to use the following CPU instructions in performance critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA (Specifically, Intel MKL-DNN is optimized for Intel® Xeon® processors and Intel® Xeon Phi™ processors). Package installation steps are
conda install tensorflow
conda install -c anaconda tensorflow-mkl
conda install matplotlib pandas scikit-learn keras



No comments: