Faster RCNN PyTorch Download, Train and Test on COCO 2014 dataset

1) Get the files from Ruotian Luo's github repository.
     git clone https://github.com/ruotianluo/pytorch-faster-rcnn.git
2) Get into the faster rcnn directory
     cd pytorch-faster-rcnn/
3) Determine your achitecture. My GPU model is nVidia Tesla P100 and  so the corresponding architecture according to this website is sm_60. The architecture will be provided to set the Nvidia Cuda Compiler's(nvcc) -arch flag in the 4th step below.
4) Compile and Build RoI Pooling module
     cd lib/layer_utils/roi_pooling/src/cuda
     nvcc -c -o roi_pooling_kernel.cu.o roi_pooling_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_60
     cd ../../
     python build.py

     cd ../../../
5) Compile and Build Non-maximum Suppression(NMS) module
     cd lib/nms/src/cuda
     nvcc -c -o nms_kernel.cu.o nms_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_60
     cd ../../
     python build.py
     cd ../../

 6) Install python COCO API under data folder.
     cd data
     git clone https://github.com/pdollar/coco.git
     cd coco/PythonAPI
     make
     cd ../../..

7) (OPTIONAL) In case your COCO data set(images and annotation) have to reside under a different directory you can create a symbolic link to it under data folder.
#move all files under coco (obtained after 6th step above) to shared coco folder
     mv data/coco/* /YOURSHAREDDATASETS/coco
#create symbolic link to that coco folder
     cd data
     rm -rf coco
     ln -s
/YOURSHAREDDATASETS/coco coco
8) Download proposals and annotation json files from here
9) After you downloaded annotations, place them under coco/annotations folder. The coco folder structure should look like below. To download default COCO images and annotations please check here.

coco/
        annotations/
                             instances_minival2014.json
                             instances_valminusminival2014.json
                             ...(default coco json files)
        images/
                    train2014/...
                    val2014/...
                    test2014/...
        PythonAPI/...
10) Create imagenet_weights folder under data. A pre-trained model on ImageNet dataset will reside here.
     mkdir -p data/imagenet_weights
11) Download the pre-trained ResNet model(the resnet101-caffe one) model from here into the imagenet_weights folder and rename it.
    cd data/imagenet_weights
    mv resnet101-caffe.pth res101.pth
     cd ../..   

12)Run training script
     GPU_ID=0
     DATASET=coco
     MODEL=res101 
     ./experiments/scripts/train_faster_rcnn.sh $GPU_ID $DATASET $MODEL
13) Test your model upon successful trainig.
#change the iteration number in test_faster_rcnn.sh to
#the number of iterations you made. I made 460000 iterations the default is 490000. 
     GPU_ID=0
     DATASET=coco
     MODEL=res101 
     ./experiments/scripts/test_faster_rcnn.sh $GPU_ID $DATASET $MODEL




Install NVIDIA Driver on Ubuntu 16.04 LTS

1) Log out from GUI

2) Open a terminal (tty) by using the Ctrl + Alt + F6 key combinations.

3) Login to the system by typing your username and password

4) Stop X-server:
    sudo service lightdm stop

5) Disable nouveau driver
    - Create the following file /etc/modprobe.d/blacklist-nouveau.conf 
    - Inside the file write those two lines :
     blacklist nouveau 
     options nouveau modeset=0

6) Update the kernel
    sudo update-initramfs -u

7) Download latest compatible NVIDIA driver from NVIDIA web site( http://www.nvidia.com/Download/index.aspx ) My driver was NVIDIA-Linux-x86_64-384.59.run

8) To install the NVIDIA driver, make sure that you have the right version of the gcc chosen. For my NVIDIA driver, I needed to choose gcc 5.0. To achieve this use
    sudo update-alternatives --config gcc 

9) Uninstall previously installed NVIDIA drivers
    sudo apt-get purge nvidia-*
    sudo apt autoremove

10) Run installation file.
      sudo sh NVIDIA-Linux-x86_64-384.59.run

11) Check if you succesfully installed the driver. The following command should print your NVIDIA driver version ang GPU Memory Usage.
     nvidia-smi

 12) Start X-server
     sudo service lightdm start

Python Line Profilers using Decorator Pattern

You can use any of the following decorators to profile your functions line by line.  The first one(Profiler1) is a decorator as a class and...