Skip to content

Instantly share code, notes, and snippets.

@zby
Last active July 26, 2021 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zby/e3341751f54bc92ebcc1d9da08a9459a to your computer and use it in GitHub Desktop.
Save zby/e3341751f54bc92ebcc1d9da08a9459a to your computer and use it in GitHub Desktop.
Installation of Python TensorFlow Object Detection libs
# tested on Ubuntu 20.04 and 21.04
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
# UNZIP INSTALLATION
sudo apt-get -y install unzip
# PYTHON 3 INSTALLATION
sudo apt-get -y install python3
sudo update-alternatives --remove-all python3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3
sudo apt-get -y install python3-venv python3-dev python3-setuptools
sudo apt-get -y install python3-pip python3-wheel
sudo apt-get -y install gcc libpq-dev
sudo apt-get -y install libxml2-dev libxslt1-dev
sudo apt-get -y install python3-lxml
sudo apt-get -y install virtualenv
sudo apt-get -y install python3-tk
sudo apt-get -y install git
# DOWNLOADING stuff
[ -d models-master/research ] || git clone https://github.com/tensorflow/models.git models-master
# maybe we should install protoc in ~/.local/bin?
[ -f protoc-3.15.6-linux-x86_64.zip ] || wget https://github.com/protocolbuffers/protobuf/releases/download/v3.15.6/protoc-3.15.6-linux-x86_64.zip
[ -d /opt/protocolbuffers ] || sudo mkdir /opt/protocolbuffers
sudo unzip protoc-3.15.6-linux-x86_64.zip -d /opt/protocolbuffers
sudo chmod a+rx /opt/protocolbuffers/bin/
sudo chmod a+rx /opt/protocolbuffers/bin/protoc
[ -d cocoapi/PythonAPI ] || git clone https://github.com/cocodataset/cocoapi.git
[ -d ~/.venvs ] || mkdir ~/.venvs
cd downloaded_models/
[ -f ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz ] || wget http://download.tensorflow.org/models/object_detection/tf2/20200711/ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz
[ -d ssd_mobilenet_v2_320x320_coco17_tpu-8 ] || tar -xzf ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz
####### CUDA INSTALL
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt update
sudo apt -y install cuda
sudo apt -y install libcudnn8 libcudnn8-dev
# tar -xzvf cudnn-11.2-linux-x64-v8.1.1.33.tgz
# sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
# sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
# sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
cd /usr/local/
sudo ln -s cuda-11.3 cuda-11.2
cd cuda-11.3/lib64
sudo ln -s libcusolver.so.11 libcusolver.so.10
########## this creates a clean lego_env local python env
P_PATH=`pwd`
# CREATE Virutalenv
deactivate
rm -rf ~/.venvs/lego_env
virtualenv ~/.venvs/lego_env
[ -f ~/.venvs/lego_env/bin/activate ] || die "No lego_env activator"
source ~/.venvs/lego_env/bin/activate
which pip # just for debugging - to be removed
pip3 install pytest
pip3 install tensorflow
pip3 install lxml==4.6.3
pip3 install PyQt5==5.15.4
pip3 install Cython==0.29.22
pip3 install parmap==1.5.2
pip3 install numpy==1.19.5
pip3 install pillow
pip3 install kiwisolver
pip3 install cycler
pip3 install pycocotools --no-build-isolation --no-binary :all:
# https://stackoverflow.com/a/66743692/356679
pip3 install mean_average_precision
pip3 install icecream
pip freeze # just for debugging - to be removed
# TF OBJECT DETECTION API INSTALLATION
cd $P_PATH/models-master/research
git clean -df
/opt/protocolbuffers/bin/protoc object_detection/protos/*.proto --python_out=.
cd $P_PATH/models-master/research
cp object_detection/packages/tf2/setup.py .
pip3 install .
########### end of repeatable part
# testing if the installation is OK
pip freeze # just for debugging - to be removed
export TF_FORCE_GPU_ALLOW_GROWTH='true'
python $P_PATH/models-master/research/object_detection/model_lib_tf2_test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment