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.
DirectX 12 & DirectML
YOLO (v3/v4/v5 variants)
Windows 10/11
C++
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:
To build and run this sample, you'll need:
You can find the complete source code and instructions on the official DirectML-Samples GitHub repository.
View Sample on GitHubHere'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)
// ...
Dive deeper into DirectML and its capabilities for machine learning acceleration on Windows: