When you have a computer vision project where you need to detect small objects, using the SAHI technique can help improve detection accuracy.
SAHI is a technique where you split a large image up into smaller images, run inference on each smaller image individually, then stitch together the results.
Here is an example of an image run without (left) and with (right) SAHI:
With Roboflow Workflows, you can build a system that detects small objects, using the SAHI technique, with any model trained on or uploaded to Roboflow in a few minutes.
In this guide, we will build a small object detection pipeline with Image Slicer, the Workflows SAHI implementation.
Here is an example of a Workflow that can detect 80 common objects, including cats, people, and cars. You can try it out to see how the model performs with and without SAHI:
Without further ado, let’s start building a Workflow!
Small Object Detection with Image Slicer
Roboflow Workflows has a block called Image Slicer that slices an input image into smaller pieces. These image segments can be run individually through an object detection model. The detections can then be stitched back together.
A workflow that uses Image Slicer will use the following steps:
- Accept an input image.
- Slice the image with Image Slicer.
- Run an object detection model.
- Stitch the results back together with the Detections Stitch block.
You can also use any of the Workflows visualization blocks (i.e. bounding boxes) to visualize the results from the system.
Here is the Workflow we are going to build, with all the steps mentioned above:
Step #1: Create a Workflow
To get started, first create a free Roboflow account. Then, navigate to the Roboflow dashboard and click the Workflows tab in the left sidebar. This will take you to the Workflows homepage, from which you can create a workflow.
Click “Create Workflow” to create a Workflow.
A window will appear in which you can choose from several templates. For this guide, select “Custom Workflow”:
Click “Create Workflow” to create your Workflow.
You will be taken into the Workflows editor in which you can configure your Workflow:
With a blank Workflow ready, we can start using the Image Slicer.
Step #2: Add Image Slicer
Click “Add Block” in the top right corner of the Workflows editor and add an Image Slicer block:
Step #3: Add a Model
Next, we need to add a model through which we want to run our image slices.
Add an Object Detection block:
Make sure the block accepts the slices from your Image Slicer block:
In the Model field, you can set the ID of any model in your Roboflow workspace, or any model hosted on Roboflow Universe.
For this guide, we are going to use yolov8n-640. This is a YOLOv8 nano model that was trained on the Microsoft COCO dataset. This model can identify a variety of common objects, including cars and cell phones.
Click on the “Model” field to select a model in your workspace, or set a model ID from Roboflow Universe.
Step #4: Stitch Detections
So far, our Workflow slices an input image, then runs inference on each slice. We need to combine the detections to complete our use of the SAHI technique for small object detection.
You can use the Detections Stitch block to combine detections. Add a Detections Stitch block:
Set the image input as the Image Slicer images, and the detections input as the detections from your object detection model:
Step #4: Add a Visualizer
Roboflow Workflows supports several visualizers that plot detections from vision models.
For this guide, let’s add two visualizers:
- A bounding box visualizer, which will draw bounding boxes from our model, and;
- A label visualizer, which will add prediction labels on top of the bounding boxes.
Add these visualizers from the Add Block panel.
Connect the Bounding Box Visualizer to the input image and use the detections from the Detections Stitch block:
Connect the Label Visualization to the Bounding Box Visualization:
We now have all the blocks we need to detect small objects with our Workflow and visualize the results.
Step #5: Test the Workflow
Your final Workflow should include the following steps:
This Workflow:
- Accepts an input image.
- Slices the image.
- Runs an object detection model on each slice.
- Stitches the detections back together.
- Visualizes the detections with bounding boxes and labels.
To test the Workflow, click “Run Preview” at the top of the Workflows editor. Then, drag in the image you want to use:
Click “Run Preview” to run the Workflow.
The result from the Workflow will appear on the right panel. Click “Show Visual” on the right panel to see detections from the system.
Here are the results of our system with Image Slicer:
For reference, here are the results without Image Slicer, computed by only using the object detection block and visualizers without the Image Slicer:
Our SAHI-based small object detection Workflow detects substantially more objects than the same Workflow that only uses an object detection model.
Deploy Your Workflow
You can deploy a Workflow in three ways:
- To the Roboflow cloud using the Roboflow API;
- On a Dedicated Deployment server hosted by Roboflow and provisioned exclusively for your use, or;
- On your own hardware.
The Workflows deployment documentation walks through exactly how to deploy Workflows using the various methods above.
Deploying to the cloud is ideal if you need an API to run your Workflows without having to manage your own hardware. With that said, for use cases where reducing latency is critical, we recommend deploying on your own hardware.
If you deploy your model in the Roboflow cloud, you can run inference on images. If you deploy on a Dedicated Deployment or your own hardware, you can run inference on images, videos, webcam feeds, and RTSP streams.
To deploy a Workflow, click “Deploy Workflow” on any Workflow in your Roboflow Workspace. A window will then open with information about how you can deploy your Workflow.
Conclusion
You can apply the SAHI small object detection technique to detect small objects in an image using the Image Slicer block in Roboflow Workflows.
In this guide, we walked through how to use Roboflow Workflows, a web-based computer vision application builder. We built a Workflow that uses the Image Slicer block, an object detection model, and the Detections Stitch block to detect small objects.
To learn more about applications you can build with Roboflow Workflows, refer to the Workflows Template gallery. To explore more blocks available in Workflows, refer to the Workflow Blocks gallery.
Cite this Post
Use the following entry to cite this post in your research:
James Gallagher. (Sep 4, 2024). Detect Small Objects with Roboflow Workflows. Roboflow Blog: https://blog.roboflow.com/small-object-detection-workflow/
Discuss this Post
If you have any questions about this blog post, start a discussion on the Roboflow Forum.