DirectML YOLO Object Detection Sample

Explore how to implement real-time object detection using the You Only Look Once (YOLO) model with DirectML on Windows. This sample showcases the power of DirectML for accelerating deep learning inference on a wide range of DirectX 12-capable hardware.

Framework

DirectX 12 & DirectML

Model

YOLO (v3/v4/v5 variants)

Platform

Windows 10/11

Language

C++

Overview

This sample demonstrates the integration of a pre-trained YOLO model for object detection within a Windows application using DirectML. You'll learn how to:

Key Features

Getting Started

To build and run this sample, you'll need:

Download the Sample

You can find the complete source code and instructions on the official DirectML-Samples GitHub repository.

View Sample on GitHub

Code Snippet Example

Here's a glimpse into how a model might be initialized for DirectML inference:


// Assume 'device' is a valid IDMLDevice
// Assume 'modelPath' is the path to your ONNX model file

Microsoft::WRL::ComPtr<IDMLOperatorSet> operatorSet;
device->GetOperatorSet(DML_OPERATOR_SET_VERSION_1_0, &operatorSet);

// Load the ONNX model
auto model = DirectML::Model::LoadFromFile(modelPath.c_str(), operatorSet.Get());

// Create an inference session
auto session = DirectML::InferenceSession::Create(device.Get(), model);

// Prepare input tensors (e.g., image data)
// ...

// Execute inference
auto outputs = session->Execute(inputs);

// Process outputs (e.g., bounding boxes, confidence scores)
// ...
            

Learn More

Dive deeper into DirectML and its capabilities for machine learning acceleration on Windows: