Setting up environment for YOLOv3

(Laptop users attention: Getting your discrete gpu to work will be a driver-nightmare)

Setting up server

Creating access point for remote work

Config changes on 01-network-manager-all.yaml

network:
ethernets:
   enp1s0:
     addresses: [192.168.1.2/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [1.1.1.1,8.8.8.8]
     dhcp4: no
 version: 2

And on our router we enabled port-forwarding to a desired port.

Installations

Nvidia drivers

First off we’ll download NVidia drivers, let’s start by adding nvidia ppa:latest,

sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update

Install NVidia drivers,

sudo apt-get install nvidia-driver-410

And reboot

sudo reboot

CUDA installation

Head on to the download page, download the needed file and proceed with instructions.

sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda

We had trouble with apt-get so we used aptitude.

sudo apt-get install aptitude
sudo aptitude install cuda

Reboot and try out nvidia-smi

nvidia-smi

OpenCV3

This is taken from the OpenCV3 installation page.

Install OS libraries

sudo apt-get update
sudo apt-get upgrade

sudo apt-get remove x264 libx264-dev

sudo apt-get install build-essential checkinstall cmake pkg-config yasm
sudo apt-get install git gfortran
sudo apt-get install libjpeg8-dev libjasper-dev libpng12-dev

sudo apt-get install libtiff5-dev

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get install libxine2-dev libv4l-dev
sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libvorbis-dev libxvidcore-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install x264 v4l-utils

sudo apt-get install libprotobuf-dev protobuf-compiler
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

sudo apt-get install python-dev python-pip python3-dev python3-pip
sudo -H pip2 install -U pip numpy
sudo -H pip3 install -U pip numpy

Install Python libraries

sudo pip3 install virtualenv virtualenvwrapper
echo "# Virtual Environment Wrapper"  >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc

mkvirtualenv facecourse-py3 -p python3
workon facecourse-py3

pip install numpy scipy matplotlib scikit-image scikit-learn ipython
// Exit virtual environment with deactivate
deactivate

Download OpenCV3 from Github

git clone https://github.com/opencv/opencv.git
cd opencv 
git checkout 3.3.1 
cd ..

Download opencv_contrib from Github

git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 3.3.1
cd ..

Compile and install OpenCV with contrib modules
Create a build directory

cd opencv
mkdir build
cd build

Run CMake

cmake -D CMAKE_BUILD_TYPE=RELEASE \
  -D CMAKE_INSTALL_PREFIX=/usr/local \
  -D INSTALL_C_EXAMPLES=OFF \
  -D INSTALL_PYTHON_EXAMPLES=OFF \
  -D WITH_TBB=ON \
  -D WITH_V4L=ON \
  -D WITH_QT=ON \
  -D WITH_OPENGL=ON \
  -D WITH_GSTREAMER=ON \
  -D WITH_CUDA=ON \
  -D WITH_NVCUVID=ON \
  -D ENABLE_FAST_MATH=1 \
  -D CUDA_FAST_MATH=1 \
  -D WITH_CUBLAS=ON \
  -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" \
  -D BUILD_opencv_cudacodec=OFF \
  -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
  -D BUILD_EXAMPLES=OFF ..

Compile and Install

# find out number of CPU cores in your machine
nproc
# substitute 4 by output of nproc
make -j 24
sudo make install
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

Create symlink in virtual environment

find /usr/local/lib/ -type f -name "cv2*.so"

cd ~/.virtualenvs/facecourse-py3/lib/python3.6/site-packages
ln -s /usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so cv2.so

Test it with C++

# compile
# There are backticks ( ` ) around pkg-config command not single quotes
g++ -std=c++11 removeRedEyes.cpp `pkg-config --libs --cflags opencv` -o removeRedEyes
# run
./removeRedEyes

workon facecourse-py3

Test with Python3

python removeRedEyes.py
// Exit virtual environment with deactivate
deactivate

Installing Darknet

git clone https://github.com/pjreddie/darknet.git
cd darknet
make
# No errors? Continue with running ./darknet

./darknet
# Output should look like:
# usage: ./darknet <function>

Edit the Makefile in the base directory to get Darknet to use your CUDA/GPU:

GPU=1

Also change the 2nd line of the Makefile:

OPENCV=1
# Try it with:
# ./darknet imtest data/eagle.jpg

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.