Last active
July 15, 2017 16:00
-
-
Save hrshovon/7cf87a48bb8f698ce3cdf4d1b5ff6110 to your computer and use it in GitHub Desktop.
py-faster-rcnn: my attempt of building
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is how I managed to build py-faster-rcnn on my fresh installed 64bit Ubuntu 16.04.For those who dont know, py-faster-rcnn | |
if a caffe based python implementation of faster-rcnn for image localization. This is more of a note for me. | |
WARNING: My methods may not work for everyone and may be for the later versions. | |
This is a GPU supported build. Make sure you have an nvidia gpu(as recent as possible,I have a GTX 1050 Ti, and yes I know | |
it's by no means a very good gpu for the task.But it handles things nicely.). | |
Now I am also running Tensorflow-gpu installed via pip. That requires cuda toolkit 8.0 and cudnn 5.1 | |
So,if we are to start from scratch, | |
1.Download cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb from nvidia website. | |
2.Run sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb. This would add some repositories and may be some other tools. | |
3.Run sudo apt-get update && sudo apt-get install cuda | |
4.This should take care of installation of cuda-toolkit. | |
5.Now you would need cudnn 5.1. This for some reason cannot be obtained without creating a free account. So create the account and | |
download the tar.gz file.(There is also a deb file but I am simply writing what I did). | |
6.Extract the cudnn directory anywhere. | |
7.Assuming you are on the parent directory of extracted cuda directory(the extracted directory is supposted to have the name "cuda"),run | |
the following commands, | |
sudo cp cuda/include/cudnn.h /usr/local/cuda/include | |
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 | |
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* | |
8.Now open ~/.bashrc with your favourite editor(nano,gedit) and insert the following lines, | |
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64" | |
export CUDA_HOME=/usr/local/cuda | |
Note: If you see that the first line is already there,simply add the second line only. | |
Save and exit. | |
run source ~/.bashrc | |
9.This probably took care of the cuda part. Now comes the super messy py-faster-rcnn part. I do hope I am adding every single | |
thing | |
I did. | |
Install dependencies for caffe, | |
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev | |
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler | |
sudo apt-get install libatlas-base-dev | |
Note: Again,saying that this may not be all.So if an error occurs, please check the error and google it. If it's some missing | |
header file, it would most likely be a missing development package or library. Google and install. | |
Some of the instructions were fetched from https://gist.github.com/titipata/f0ef48ad2f0ebc07bcb9 | |
10.Install/build opencv. | |
For this, I ran sudo apt-get install python-opencv.This took care of some of the dependencies. | |
Then I downloaded opencv 3.2 source zip from their site and extracted it. | |
Then I entered the opencv source directory and ran the following commands. | |
mkdir build | |
cd build/ | |
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. | |
make -j4 | |
Note: If you are not doing anything, you can replace -j4 with -j8 on a quad core system or may be higher in a system with more cores, | |
such as an i7,xeon or ryzen based system. | |
This is gonna take REAL long tym.So wait for it and hope that you dont get any errors. | |
After this is done, run the following commands, | |
sudo make install | |
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' | |
sudo ldconfig | |
sudo apt-get update | |
No idea whats the deal with the last apt-get update though.Got this from https://github.com/intel/caffe/wiki/Ubuntu-16.04-or-15.10-OpenCV-3.1-Installation-Guide | |
11.Open a terminal and run python. | |
When python console opens,run, | |
import cv2 | |
cv2.__version__ | |
it should show '3.2.0' | |
Then you are done with opencv3. yay! | |
12.Now get to your home directory ~/<user>(example, you can do it anywhere). and run git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git | |
(Hope you have git installed,if not then run sudo apt-get install git) | |
13.Run sudo pip install pyaml | |
sudo pip install easydict. (The ./tools/demo.py needs those,not sure about the rest) | |
14.Now some housekeeping for the old caffe code that was downloaded with py-faster-rcnn. | |
cd caffe-fast-rcnn | |
git remote add caffe https://github.com/BVLC/caffe.git | |
git fetch caffe | |
git merge -X theirs caffe/master | |
if some of these commands puts you in identity crisis like who you are or something, just copy and paste one of the commands | |
listed in the error message.I usually choose the one with email address and add my address. This would happen to those who hasn't created a repository. | |
Then after all that, | |
Remove self_.attr("phase") = static_cast<int>(this->phase_); from include/caffe/layers/python_layer.hpp | |
you are hopefully good to go now. | |
15.cd to caffe-fast-rcnn. | |
now run cp Makefile.config.example Makefile.config. | |
then gedit Makefile.config(pluma Makefile.config for ubuntu mate users) | |
Now do the following, | |
i. Uncomment USE_CUDNN := 1 | |
ii. Uncomment OPENCV_VERSION := 3 | |
iii. Change the line CUDA_DIR := /usr/local/cuda to CUDA_DIR := /usr/local/cuda-8.0 | |
iv. Uncomment WITH_PYTHON_LAYER := 1 | |
v. Change the INCLUDE_DIRS and LIBRARY_DIRS lines right below the aforementioned line to, | |
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial | |
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/ | |
Save and exit. | |
vi. Run gedit Makefile and change the 2nd(probably) LIBRARIES line to, | |
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl | |
Save and exit. | |
vii. Now run make all -j4(or j8 or more) | |
ix. If this completes without any errors, then you are most likely safe. Run, | |
make pycaffe | |
make distribute. | |
x. Add the following line to ~/.bashrc | |
export CAFFE_ROOT=/home/shovon/py-faster-rcnn/caffe-fast-rcnn/ | |
export PYTHONPATH=/home/shovon/py-faster-rcnn/caffe-fast-rcnn/distribute/python:$PYTHONPATH | |
export PYTHONPATH=/home/shovon/py-faster-rcnn/caffe-fast-rcnn/python:$PYTHONPATH | |
xi. then cd to py-faster-rcnn and run, | |
cd lib | |
make | |
xii. Now cd to py-faster-rcnn and run, | |
./data/scripts/fetch_faster_rcnn_models.sh | |
This should download some models and datasets may be. | |
xiii.Run ./tools/demo.py. If everything goes right, you should see some pictures with detected objects. | |
xiv. Congratulations. You are done. Install anything that is required. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment