HOWTO: Install TensorFlow with CUDA GPU support on CentOS 7

a) Install Python 3.7.9 (see Python)

b) Create and activate new virtual environment called ‘tf220-py379’

sudo python3 -m venv /opt/venv/tf220-py379
source /opt/venv/tf220-py379/bin/activate.sh

c) Upgrade ‘pip’ and install TensorFlow 2.2.0

sudo /opt/venv/tf220-py379/bin/python3 -m pip install --upgrade pip
sudo pip install --ignore-installed --upgrade tensorflow==2.2.0

d) Test Tensorflow works correctly:

python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

e) Install NVIDIA’s CUDA:

sudo yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
sudo yum clean all
sudo yum install nvidia-driver-latest-dkms cuda-11.0.x86_64 cuda-cudart-11-0.x86_64 libcublas-11-0.x86_64 libcusparse-11-0.x86_64 libcudnn8.x86_64

f) Modify environment variables to enable CUDA:

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda-10.2/targets/x86_64-linux/lib:$LD_LIBRARY_PATH

g) Install latest NVIDIA driver:

Remove and blacklist 'default' Nouveau driver

modprobe -r -b nouveau

Install prerequisite packages

sudo yum -y install kernel-devel

Find out specification of NVIDIA card with

lspci

Download latest driver for your system from

https://www.nvidia.com/Download/index.aspx

Install latest driver

chmod +x ./NVIDIA-Linux-x86_64-460.73.01.run
sudo ./NVIDIA-Linux-x86_64-460.73.01.run

Install additional CUDA packages/libraries

sudo yum -y install cuda-cudart-11-3.x86_64

h) Verfity TensorFlow uses GPUs

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

HOWTO: Install TensorFlow Object Detection API

a) Ensure Linux user has write permisions to ‘/opt/tf’ and ‘/opt/venv’ directories

sudo chown pxb84596 -R /opt/tf /opt/venv
sudo chmod u+w -R /opt/venv/ /opt/tf

b) Download TensorFlow model garden and place ‘models’ under your TensorFlow work directory ‘/opt/tf’

https://github.com/tensorflow/models

c) Download, compile and install ‘protoc’ to ‘/opt/protoc’, modify ‘PATH’ environment variable to enable ‘protoc’ usage

https://github.com/google/protobuf/releases

d) Launch protoc on object detection models

cd /opt/tf/models/research
protoc object_detection/protos/*.proto --python_out=.

e) Install COCO API

git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
make
cp -r pycocotools /opt/tf/models/research

f) Install Object Detection API

cd /opt/tf/models/research
cp object_detection/packages/tf2/setup.py .
/usr/bin/python3 -m pip install .

g) Test Object Detection installation

cd /opt/tf/models/research
python object_detection/builders/model_builder_tf2_test.py