Detect Small Objects with supervision.InferenceSlicer
¶
This cookbook shows how to use Slicing Aided Hyper Inference (SAHI) for small object detection with supervision
.
Click the Open in Colab button to run the cookbook on Google Colab.
Before you start¶
You'll need:
- A free Roboflow account. Don't have one? Create one here.
- An API key from Roboflow. Need help getting one? Learn more here.
Install required packages¶
Let's install the dependencies for this project. Here's a list of what
inference
: a package by Roboflow for easy deployment of computer vision models.supervision
: a package by Roboflow that provides utilities for building and managing computer vision applications.
%pip install inference supervision jupyter_compare_view
Crowd counting with Computer Vision¶
How would you go about solving the problem of counting people in crowds? After some tests, I found that the best approach is to detect people’s heads. Other body parts are likely occluded by other people, but heads are usually exposed, especially in aerial or high-level shots.
Using an Open-Source Public Model for People Detection¶
Detecting people (or their heads) is a common problem that has been addressed by many researchers in the past. In this project, we’ll use an open-source public dataset and a fine-tuned model to perform inference on images.
Some details about the project "people_counterv0 Computer Vision Project":
- Dataset of 4,574 images
- mAP=49.2% / Precision=74.5% / Recall=39.2
- Model: Roboflow 2.0 Object Detection (fast)
- Checkpoint: COCOv6n
- Created by: SIT
Imports¶
Run the code below to download to load the modules necessarry for this cookbook
import math
import os
import time
import cv2
import matplotlib.pyplot as plt
import numpy as np
import supervision as sv
from inference import get_model
from jupyter_compare_view import compare
Download Image¶
# Download the image
!wget -O human_tower.jpg "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/4_de_8_amb_l%27agulla_carregat_Castellers_de_Barcelona_%2821937141066%29.jpg/2560px-4_de_8_amb_l%27agulla_carregat_Castellers_de_Barcelona_%2821937141066%29.jpg"
image = cv2.imread("human_tower.jpg")
image_wh = (image.shape[1], image.shape[0])
print(f"Image shape: {image_wh[0]}w x {image_wh[1]}h")
sv.plot_image(image)
Image shape: 2560w x 1696h