Implementation:Tencent Ncnn MobileNetV3 SSDLite Example
| Knowledge Sources | |
|---|---|
| Domains | Vision, Object Detection |
| Last Updated | 2026-02-09 19:00 GMT |
Overview
Concrete tool for object detection on PASCAL VOC classes using MobileNetV3 SSD-Lite with ncnn and optional Vulkan GPU acceleration.
Description
This example demonstrates MobileNetV3 SSD-Lite object detection using the ncnn framework. It loads a converted MobileNetV3-SSDLite model, performs BGR-to-RGB conversion, resizes to 300x300, and applies ImageNet-style mean subtraction (123.675, 116.28, 103.53). A clamp utility function filters out cross-boundary detections that fall outside valid coordinate ranges. Vulkan GPU compute is conditionally enabled based on compile-time support via the NCNN_VULKAN preprocessor flag. Detections above a 0.6 confidence threshold are drawn with bounding boxes.
Usage
Use this example when you need to perform multi-class object detection with a MobileNetV3 backbone. It is suitable when Vulkan GPU acceleration is available and desired. The confidence filtering at 0.6 makes it appropriate for scenarios where higher precision is preferred over recall.
Code Reference
Source Location
- Repository: Tencent_Ncnn
- File: examples/mobilenetv3ssdlite.cpp
- Lines: 1-164
Signature
template<class T>
const T& clamp(const T& v, const T& lo, const T& hi);
static int detect_mobilenetv3(const cv::Mat& bgr, std::vector<Object>& objects);
static void draw_objects(const cv::Mat& bgr, const std::vector<Object>& objects);
int main(int argc, char** argv);
Import
#include "net.h"
#include "platform.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| image_path | const char* | Yes | Path to input image (passed as command-line argument) |
| bgr | const cv::Mat& | Yes | BGR image loaded by OpenCV, converted to RGB and resized to 300x300 |
Outputs
| Name | Type | Description |
|---|---|---|
| objects | std::vector<Object> | Detected objects with label, prob, and rect; only those with prob > 0.6 are drawn |
| Visual output | cv::imshow window | Displayed image with bounding boxes and class labels for high-confidence detections |
Model Files
| File | Description |
|---|---|
| mobilenetv3_ssdlite_voc.param | Network parameter file |
| mobilenetv3_ssdlite_voc.bin | Network weight file |
Preprocessing
- Color conversion: BGR to RGB via
ncnn::Mat::PIXEL_BGR2RGB - Resize: Input resized to 300x300
- Mean values: [123.675, 116.28, 103.53]
- Norm values: [1.0, 1.0, 1.0] (no scaling applied)
- Coordinate clamping: Detected box coordinates are clamped to [0, target_size-1] to filter cross-boundary detections
Usage Examples
Running the Example
./mobilenetv3ssdlite image.jpg
Key Code Pattern
ncnn::Net mobilenetv3;
#if NCNN_VULKAN
mobilenetv3.opt.use_vulkan_compute = true;
#endif
mobilenetv3.load_param("./mobilenetv3_ssdlite_voc.param");
mobilenetv3.load_model("./mobilenetv3_ssdlite_voc.bin");
ncnn::Mat in = ncnn::Mat::from_pixels_resize(bgr.data, ncnn::Mat::PIXEL_BGR2RGB,
bgr.cols, bgr.rows, 300, 300);
const float mean_vals[3] = {123.675f, 116.28f, 103.53f};
const float norm_vals[3] = {1.0f, 1.0f, 1.0f};
in.substract_mean_normalize(mean_vals, norm_vals);
ncnn::Extractor ex = mobilenetv3.create_extractor();
ex.input("input", in);
ncnn::Mat out;
ex.extract("detection_out", out);