Code for Fast Bird Part Localization part of the following paper:
Fast Bird Part Localization for Fine-Grained Categorization
Yaser Souri, Shohreh Kasaei
The Third Workshop on Fine-Grained Visual Categorization (FGVC3) in conjunction with CVPR 2015
The code for classification part is very simple and not included in this repository.
- Python 2.7. This might not work with Python 3.
- A recent installation of caffe with its python wrapper. (I have installed this version of caffe.)
- OpenCV 2.4 with its Python wrapper.
- All other python requirements are mentioned in
requirements.txt
For testing or training you need the pretrained CaffeNet network. You can download it from this url. After downloading it, make sure you change the src/settings.py
file and change the CAFFE_NET_PRETRAINED
variable accordingly.
This can be done using the CUB dataset. First download the CUB-200-2011 dataset from here and extract it.
Then change src/settings.py
file and set the CUB_FOLDER_PATH
varialble accordingly.
Then run the following command:
python create_rf_model.py
This will create a head detector for you in the models directory. To run this script you will night large amount of RAM (~30GB).
Changing part_name
variable in create_rf_model.py
file to body
instead of head
will create a detector for body.
For localization you can run something like this.
import sys
sys.path.append('/path/to/projectroot/')
from fast_bird_part_localization import settings
sys.path.append(settings.CAFFE_PYTHON_PATH)
import caffe
from fast_bird_part_localization import detector
fbp = detector('/path/to/project/models/head_model.mdl')
img = caffe.io.load_image('/path/to/bird.jpg')
head, head_prob = fbp.detect(img)
fbp.draw(img, head, head_prob)
This is the result you get:
You can also take a look at the notebook example
I'm in progress of cleaning up my original code and putting it here. So please wait a little while.
TODO:
- Extracting code from notebook about postprocessing.
- Extracting code from notebook about visualization.
- Adding description on how to use the pretrined model.
- Adding description on how to train a new model from CUB.
- Adding description on how to train a new model from own data.
- Adding code for PCP evaluation.
- Adding bounding box regression for better PCP.