Member-only story
Identifying people in photos using Python and Neural Networks
Using Facebook Research’s Detectron2 framework to identify and extract from people within a photograph

About The Series
This article is part of a 2-piece set discussing the automated filtering of photographs.
- Identifying People in Photos using Python and Neural Networks
- Neural Image Assessment: Sorting photographs by Aesthetic and Technical Quality
Background
Many situations call that we identify photographs containing people within them. This could be from a security standpoint (we need to check if we have permission to publish photographs with people faces), or automation standpoint — e.g. if trying to filter photographs from a sports event or competition.
What is Detectron2?
Facebook AI Research’s collection of state-of-the-art object detection algorithm is called Detectron. This is based on the Mask R-CNN benchmark and is written in Python and PyTorch. It supports bounding box detection, densepose detection, instance segmentation, keypoint detection, and other computer vision tools.
Examples of its usage and research papers are located here.
Installation
Unfortunately, installation is limited to Unix operating systems. Although if you have installed the Linux subsystem on Windows, this should not be a problem.
conda install -c conda-forge detectron2;
pip install -U iopath==0.1.4 omegaconf opencv-python;
Setting Up the Script
To make use of detectron we begin by creating a python script made up from the following:
Imports
As usual, we start by importing the relevant libraries.
import detectron2,cv2
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfgfrom detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog, DatasetCatalog