Install py-faster-rcnn Ubuntu on Virtual Box

This is how I install py-faster-rcnn, up to running to make sure the installation is succesful. Since we can’t virtualize graphic device, the library will be running on CPU, so there are bunch of modifications here. Replace any <user> below with your real username.

Hardware / Software

I used Dell Aspire E 15 running NVIDIA GeForce 940MX with 2 GB dedicated VRAM. The Virtual Box version is 5.1.14 r112924 with Ubuntu 16.04 installed in it (2GB RAM, 16GB VDI). I have successfully re-run these steps on Microsoft Surface Pro 3 with the same VBox and Ubuntu..

0. Virtual Box Configuration

0.1. Update Ubuntu

After Ubuntu was installed, install updates, build essentials, and latest version of kernel headers.

sudo apt-get updates

sudo apt-get install build-essential

sudo apt-get install linux-headers-`uname -r`

0.2. Install Virtual Box Additions:

Click menu Devices then click Insert Guest Addition CD Image ... The virtual CD drive will be mounted. Then in your terminal:

cd /media/<user>/VBOXADDITIONS_5.1.14_112924 

sudo ./

to install the Virtual Box additions. The name of the virtual CD drive may vary depends on your Virtual Box version. Restart your Ubuntu to make sure the additions are installed perfectly.

1. Install Dependencies

Basic packages:

sudo apt-get install -y build-essential cmake git pkg-config

Caffe dependencies:

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler gfortran libjpeg62 libfreeimage-dev libatlas-base-dev libgoogle-glog-dev libbz2-dev libxml2-dev libxslt-dev libffi-dev libssl-dev libgflags-dev liblmdb-dev

sudo easy_install pillow


sudo apt-get install -y python-dev python-pip python-yaml python-opencv

2. Install CUDA

2.1. Donwload CUDA

Download CUDA here by selecting your platform. I used CUDA 8.0 and chose runfile (local) at the last option to get the .run file.

2.2. Run the CUDA installer

Make the downloaded file runnable first

cd ~/Downloads

chmod +x

Then run the installer

sudo ./ --kernel-source-path=/usr/src/linux-headers-`uname -r`/

Hit Enter up until the option appears:

  • Accept EULA: type accept
  • Do not install graphic card drivers since we don’t have graphic card in our Virtual Box: type n
  • Install toolkit: type y
  • Enter toolkit location: jus tpress enter
  • Install symbolic link: type y
  • Install samples: type y
  • Enter CUDA samples location, in my case I leave it as is: press enter

Update the library path:

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc

echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/lib' >> ~/.bashrc

source ~/.bashrc

3. Download py-faster-rcnn

Now the easiest part, download the py-faster-rcnn

cd ~

git clone --recursive

Then create enviromental variables for py-faster-rcc and caffe-fast-rcnn folder paths.

echo 'export FRCN=/home/<user>/py-faster-rcnn' >> ~/.bashrc

echo 'export CAFFE=/home/<user>/py-faster-rcnn/caffe-fast-rcnn' >> ~/.bashrc

source ~/.bashrc

4. Compile Caffe and Pycaffe

Here comes the most annoying part because I had to do lots of adjustment back and forth, before making it work.

4.1. Install python requirements

cd $CAFFE/python

for req in $(cat requirements.txt); do pip install $req; done

pip install easydict

Add couple of symbolic links

sudo ln -s /usr/include/python2.7/ /home/<user>/.local/lib/python2.7 

sudo ln -s /home/<user>/.local/lib/python2.7/site-packages/numpy/core/include/numpy/

4.2 Edit Makefile config

In the caffe root folder ($CAFFE), copy the Makefile.config example

cp Makefile.config.example Makefile.config

gedit Makefile.config

Then edit some necessary parts:

  • uncomment CPU_ONLY and WITH_PYTHON_LAYER
# CPU-only switch (uncomment to build without GPU support). 
PYTHON_INCLUDE := /usr/include/python2.7 /home/<user>/.local/lib/python2.7/site-packages/numpy/core/include
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
CUDA_DIR := /usr/local/cuda-8.0 

4.3. Build caffe

Make sure you are inside the caffe root in your terminal, then


make pycaffe

make all

5. Build cython modules

5.1. Edit

gedit $FRCN/lib/fast_rcnn/

then set USE_GPU_NMS to FALSE.

5.2. Edit test_net and train_net

gedit $FRCN/tools/

gedit $FRCN/tools/

In both files replace caffe.set_mode_gpu() with caffe.set_mode_cpu().

5.3. Edit

cd $FRCN/lib



DELETE or comment these whole rows

        ['nms/', 'nms/gpu_nms.pyx'],
        # this syntax is specific to this build system
        # we're only going to use certain compiler args with nvcc and not with
        # gcc the implementation of this trick is in customize_compiler() below
        extra_compile_args={'gcc': ["-Wno-unused-function"],
                            'nvcc': ['-arch=sm_35',
        include_dirs = [numpy_include, CUDA['include']]

5.4. Modify

gedit $FRCN/lib/fast_rcnn/

Comment these lines:

#from nms.gpu_nms import gpu_nms

    #if cfg.USE_GPU_NMS and not force_cpu:
    #    return gpu_nms(dets, thresh, device_id=cfg.GPU_ID)

5.5. Compile the libraries

cd $FRCN/lib


6. Run Demo

If you are not getting any error from the previous steps, or finally able to figure them out and debug your errors, congratulations! Now let’s run the demo.

6.1. Download pre-computed Faster R-CNN detectors

cd $FRCN


6.2. Run demo

cd $FRCN/tools

python --cpu --net zf

If you are able to run the demo smoothly, it will show something like this Success demo

Good luck!