This project provides a complete, containerized solution for running real-time object detection using YOLOv11 with NVIDIA DeepStream 7.1. All components are orchestrated using Docker Compose.
The pipeline is designed to take multiple video streams as input, perform inference using a YOLOv11 model, and then publish the resulting metadata to a MQTT Mosquitto broker. For visual verification, it also generates a tiled video output of the processed streams.
- Containerized: The entire environment, including DeepStream, dependencies, and the MQTT broker, is managed by Docker and Docker Compose for easy setup and portability.
- YOLOv11 Integration: Uses a custom-built parser to integrate the powerful YOLOv11 model into the DeepStream pipeline. The model is converted to an ONNX format and then to a TensorRT engine for maximum performance.
- MQTT Data Sink: Publishes rich inference metadata (object class, bounding boxes, sensor info) to a Mosquitto MQTT broker, perfect for IoT applications and further event-driven processing.
- Multi-Stream Support: Configured to process four video streams in parallel.
- File Output: Generates a tiled
.mp4video file of the output, complete with bounding box overlays for visual debugging and verification.
.
├── Dockerfile
├── docker-compose.yml
├── README.md
└── configs/
├── main.txt
├── yolo11.txt
├── msgconv.txt
└── mosquitto.conf
Before you begin, ensure you have the following installed on your system (tested on AWS EC2 g4dn.xlarge):
- NVIDIA Driver: A compatible NVIDIA driver for your GPU.
- NVIDIA Container Toolkit: To enable GPU support within Docker containers.
- Docker: The latest version of Docker.
- Docker Compose: The latest version of Docker Compose.
-
Clone the Repository
git clone https://github.com/feli-santos/containerized-deepstream-yolo-mosquitto.git cd containerized-deepstream-yolo-mosquitto -
Review Configurations (Optional)
configs/main.txt: The main DeepStream application config. Here you can change video source paths, enable/disable sinks, and adjust pipeline properties.configs/yolo11.txt: The configuration for the YOLOv11 model, including the path to the ONNX model file and custom library.configs/msgconv.txt: Defines the metadata for each camera/sensor that will be published to MQTT.docker-compose.yml: Defines the services, volumes, and networks.
-
Build and Run the Containers Execute the following command from the root of the project directory:
docker compose up --build
- The
--buildflag is necessary on the first run to build the custom Docker image defined in theDockerfile. - First-Time Run: The initial build will take several minutes. After the build, when the
deepstream-appstarts for the first time, it will take a few more minutes to build the YOLOv11 TensorRT.enginefile. This is a one-time process for your specific GPU architecture. Subsequent runs will be much faster.
- The
Once the containers are running, you can verify the output in two ways:
The pipeline is configured to save a tiled video of the processed streams to /app/output/deepstream_output.mp4 inside the container, which is mounted to the local ./output directory.
- The output file will be automatically saved to the
output/directory in your project folder asdeepstream_output.mp4.
The primary output is the metadata sent to the Mosquitto MQTT broker. You can subscribe to the deepstream_topic to see the real-time JSON data.
- If you don't have an MQTT client, you can install
mosquitto-clientson your host machine:sudo apt-get update && sudo apt-get install mosquitto-clients - Subscribe to the topic:
You should see a continuous stream of JSON objects, each representing an object detected in the video frames.
mosquitto_sub -h localhost -t deepstream_topic -p 1883 -v
This project heavily relies on the work done in the DeepStream-Yolo repository by Marcos Luciano. A huge thank you to him for providing the custom parsers and integration logic that make running YOLO models in DeepStream possible.