Skip to content

Latest commit

 

History

History
105 lines (80 loc) · 5.73 KB

README.md

File metadata and controls

105 lines (80 loc) · 5.73 KB

Selective Search [Uijlings13] reimplementation in PyTorch

It allows to extract not only the bounding boxes, but also the region masks.

Feature computation and region merging loop is done in Python / PyTorch. The underlying graph segmentation [Felzenszwalb2004] is still OpenCV's cv2.ximgproc.segmentation.createGraphSegmentation.

This reimplementation follows the OpenCV's cv2.ximgproc.segmentation.createSelectiveSearchSegmentation. This reimplementation is slower than the original C++ (mainly due to region merging loop in Python, and PyTorch's slower computation of histogram distances), but allows for simpler experimentation.

Most of implementation should be running fine on GPU, but it is not tested yet (and the graph segmentation currently runs only on CPU anyway).

Usage

# pip install opencv-python-headless opencv-contrib-python-headless # or without -headless
# download github mirror of astronaut test image https://www.flickr.com/photos/nasacommons/16504233985/ small size: https://live.staticflickr.com/8674/16504233985_9f1060624e_w_d.jpg
# curl https://user-images.githubusercontent.com/1041752/127776719-f8abfd60-6640-48fb-8b70-a1b6f6ade5cf.jpg > ./examples/astronaut.jpg
# curl https://user-images.githubusercontent.com/1041752/138138584-6d0a07d4-5980-4da3-aace-34afa32836a1.JPEG > ./examples/n02869837_18068.JPEG
# curl https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/cv/ximgproc/model.yml.gz > ./examples/model.yml.gz

python3 demo.py --gradio

python3 demo.py -i ./examples/astronaut.jpg -o ./out/
# open test.png and test.png.gif

python3 demo.py -i ./examples/astronaut.jpg -o ./out/ --algo opencv
# open test.png

# pushd opencv_custom && make OPENCVLIBDIR=/path/to/opencv/lib/dir OPENCVINCLUDEDIR=/path/to/opencv/include/dir/opencv4 && popd
python3 demo.py -i ./examples/astronaut.jpg -o ./out/ --algo opencv_custom
# open test.png and test.png.gif

astronaut.jpg

astronaut.jpg

test.png

test.png

test.png.gif

test.png.gif

TODO

References

Credits

I copied some Kornia's color conversion utils: https://kornia.readthedocs.io/en/latest/color.html

@article{Uijlings13,
  author = {J.R.R. Uijlings and K.E.A. van de Sande and T. Gevers and A.W.M. Smeulders},
  title = {Selective Search for Object Recognition},
  journal = {International Journal of Computer Vision},
  year = {2013},
  url = {https://ivi.fnwi.uva.nl/isis/publications/2013/UijlingsIJCV2013/UijlingsIJCV2013.pdf}
}

@article{Felzenszwalb2004,
  author = {Felzenszwalb, Pedro F. and Huttenlocher, Daniel P.},
  title = {Efficient Graph-Based Image Segmentation},
  journal = {International Journal of Computer Vision},
  year = {2004},
  url = {http://people.cs.uchicago.edu/pff/papers/seg-ijcv.pdf}
}

@inproceedings{Manen2013,
  author = {Manen, Santiago and Guillaumin, Matthieu and Van Gool, Luc},
  title = {Prime Object Proposals with Randomized Prim's Algorithm},
  booktitle = {Proceedings of the IEEE International Conference on Computer Vision (ICCV)},
  year = {2013},
  url = {https://openaccess.thecvf.com/content_iccv_2013/papers/Manen_Prime_Object_Proposals_2013_ICCV_paper.pdf}
}

More references