Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Tencent Ncnn SqueezeNetSSD Example

From Leeroopedia


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 SqueezeNet-SSD with ncnn, providing a lightweight detection model.

Description

This example demonstrates SqueezeNet-SSD object detection using the ncnn framework. It loads a pretrained SqueezeNet-SSD model (originally from Caffe), resizes input images to 300x300 with mean subtraction (104, 117, 123) and no normalization scaling. The model extracts the "detection_out" layer, which returns detections in the standard (label, prob, x1, y1, x2, y2) format for the 20 PASCAL VOC classes. This follows the same simple detection output parsing pattern used across the ncnn SSD-style examples, making it one of the most straightforward detection examples in the repository.

Usage

Use this example when you need a very lightweight object detector for VOC categories. SqueezeNet provides a smaller model footprint compared to MobileNet-based alternatives, making it suitable for extremely resource-constrained environments where model size is the primary concern.

Code Reference

Source Location

Signature

static int detect_squeezenet(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"

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, resized internally to 300x300

Outputs

Name Type Description
objects std::vector<Object> Detected objects with label (int), prob (float), and rect (cv::Rect_<float>)
Visual output cv::imshow window Displayed image with bounding boxes and VOC class labels

Model Files

File Description
squeezenet_ssd_voc.param SqueezeNet-SSD network parameter file
squeezenet_ssd_voc.bin SqueezeNet-SSD network weight file

Preprocessing

  • Resize: Input resized to 300x300 using ncnn::Mat::from_pixels_resize with PIXEL_BGR
  • Mean values: [104.0, 117.0, 123.0]
  • Norm values: None (passed as 0, no normalization scaling)

Usage Examples

Running the Example

./squeezenetssd image.jpg

Key Code Pattern

ncnn::Net squeezenet;
squeezenet.opt.use_vulkan_compute = true;

squeezenet.load_param("squeezenet_ssd_voc.param");
squeezenet.load_model("squeezenet_ssd_voc.bin");

ncnn::Mat in = ncnn::Mat::from_pixels_resize(bgr.data, ncnn::Mat::PIXEL_BGR,
    bgr.cols, bgr.rows, 300, 300);

const float mean_vals[3] = {104.f, 117.f, 123.f};
in.substract_mean_normalize(mean_vals, 0);

ncnn::Extractor ex = squeezenet.create_extractor();
ex.input("data", in);

ncnn::Mat out;
ex.extract("detection_out", out);

for (int i = 0; i < out.h; i++)
{
    const float* values = out.row(i);
    // values[0]=label, values[1]=prob, values[2..5]=box coords
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment