“How can I draw a more detailed outline around an object?”
This is probably one of the most frequently asked questions I get after someone reads my previous article on how to do object detection using TensorFlow. There is good news, I finally have the answer.
Facebook AI Research (FAIR) just open sourced their Detectron platform. This means that the software that FAIR uses for object detection research is now available to all of us developers. One of the many things that this new platform can do is object masking. Object masking takes objected detection a step further and instead of just drawing a bounding box around the image, it can actually draw a complex polygon.
Detectron makes it incredibly simple to get object masking running out of the box. Here’s how:
The first step is to install Caffe2:
git clone --recursive https://github.com/caffe2/caffe2.git && cd caffe2
make && cd build && sudo make install
python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
Note: Currently, you MUST have an NVIDIA GPU with CUDA in order to use Detectron.
Install the COCO API
git clone https://github.com/cocodataset/cocoapi.git
Clone the Repo
After we successfully install Caffe2 all we need to do is clone the Detectron repo:
git clone https://github.com/facebookresearch/Detectron.git && cd Detectron
Install the requirements:
pip install \
And build the python modules:
cd lib && make && cd ..
Now all we have to do is run the following command to run object masking on the demo images:
python tools/infer_simple.py \
--cfg configs/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml \
--output-dir demo/output \
--image-ext jpg \
You’ll be able to find the output as PDFs in the
Here are some of my own test examples, most of them worked pretty well.
But as always, the Kardashians continue to stump AI, because are they real?
Note: If you want to test your own images just add JPG files to the
Detectron/demodirectory. For best results keep the images around 600–800px.
This model does a great job at masking very general objects, however a lot of us need something more specific to our use case. For that, keep a look out for my next tutorial on how to build your own custom object masking model!
If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.