Skip to content

GPU Batch Object Detection

The GPU Batch Object Detection workflow allows you to efficiently process large volumes of images using pre-trained object detection models. This implementation leverages Machine GPU runners to accelerate detection tasks, making it possible to analyze thousands of images in a fraction of the time required by CPU-only solutions.

Prerequisites

You will need to have completed the Quick Start guide.

Use Case Overview

Why might you want to use GPU-accelerated batch object detection?

  • Process large collections of images efficiently
  • Extract and analyze objects, people, vehicles, or other entities
  • Generate metadata and annotations for computer vision datasets
  • Create analytics from visual content without manual intervention

How It Works

The GPU Batch Object Detection workflow uses the DETR model (facebook/detr-resnet-50) with Hugging Face Transformers to detect and annotate objects in images. The workflow is defined in GitHub Actions and can be triggered on-demand with configurable parameters.

The detection process:

  1. Sets up the necessary environment with GPU support
  2. Downloads images from the COCO2017 dataset
  3. Processes the images using the DETR object detection model
  4. Generates annotated results and a CSV file with detection details
  5. Uploads the results as a GitHub Actions artifact

Workflow Implementation

The GPU Batch Object Detection is implemented as a GitHub Actions workflow that can be triggered manually. Here’s the workflow definition:

name: Batch Object Detection
on:
workflow_dispatch:
inputs:
tenancy:
type: choice
required: false
description: 'The tenancy of the machine'
default: 'spot'
options:
- 'spot'
- 'on_demand'
jobs:
detect_objects:
name: Detect Objects
runs-on:
- machine
- gpu=T4
- cpu=4
- ram=16
- architecture=x64
- tenancy=${{ inputs.tenancy }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Dependencies
run: |
pip install -r requirements.txt
- name: Run Object Detection
run: python3 object_detection.py
- name: Upload Detection Results CSV
uses: actions/upload-artifact@v4
with:
name: detection-results-csv
path: detection_output/detections.csv

Using Machine GPU Runners

This object detection process leverages Machine GPU runners to provide the necessary computing power for efficient image processing. The workflow is configured to use:

  • T4 GPU: An entry-level ML GPU with 16GB VRAM, well-suited for computer vision tasks
  • Spot instance: To optimize for cost while maintaining performance
  • Configurable resources: CPU, RAM, and architecture specifications

The T4 GPU provides excellent performance for batch object detection tasks, delivering significantly faster processing compared to CPU-only solutions. For larger workloads or more complex models, you can also configure the workflow to use more powerful GPUs like L4 or L40S.

Key Features

  • GPU Acceleration: Efficiently perform object detection using GPUs via Machine
  • Seamless Data Integration: Automatically fetch and process images from datasets
  • Automated Detection Pipeline: Detect, annotate, and export results without manual intervention
  • Results in CSV: Generate a structured CSV artifact with detection details for easy review
  • Easy Deployment: Use the repository as a GitHub template to quickly start your own GPU-accelerated workflows

Getting Started

To run the GPU Batch Object Detection workflow:

  1. Use the MachineHQ/gpu-batch-object-detection repository as a template
  2. Navigate to the Actions tab in your repository
  3. Select the “Batch Object Detection” workflow
  4. Click “Run workflow” and configure your parameters:
    • Choose between spot or on-demand tenancy
  5. Run the workflow and wait for results
  6. Download the detection-results-csv artifact to view the detection details

Best Practices

  • Use spot instances for non-time-critical batch processing to optimize costs
  • Adjust batch sizes to match your GPU memory capacity
  • Pre-filter your input data to reduce processing time on irrelevant images
  • Consider dataset chunking for extremely large collections of images
  • Implement progress tracking for long-running batch jobs

Next Steps