yolov5s-ghost-inference-in-cpp-from-scratch

C++ implementation of YOLOv5s-Ghost for object detection, featuring a lightweight neural network with HLS support for FPGA deployment. Performs inference on 640x640 RGB images, with NMS post-processing for 80 COCO classes. Includes Makefile for easy compilation.

https://github.com/engrbilal992/yolov5s-ghost-inference-in-cpp-from-scratch

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.5%) to scientific vocabulary
Last synced: 8 months ago · JSON representation ·

Repository

C++ implementation of YOLOv5s-Ghost for object detection, featuring a lightweight neural network with HLS support for FPGA deployment. Performs inference on 640x640 RGB images, with NMS post-processing for 80 COCO classes. Includes Makefile for easy compilation.

Basic Info
  • Host: GitHub
  • Owner: engrbilal992
  • Language: C
  • Default Branch: main
  • Size: 18.5 MB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme Citation

README.md

YOLOv5s-Ghost Inference in C++ from Scratch

Overview

This repository contains a pure C++ implementation of the YOLOv5s-Ghost object detection model, written entirely from scratch without using any external deep learning frameworks or image processing libraries. The project performs inference on 640x640 RGB images and outputs bounding box coordinates, confidence scores, and class labels for 80 COCO dataset classes.

This implementation faithfully reconstructs the YOLOv5s-Ghost architecture — including convolutional layers, Ghost modules, Spatial Pyramid Pooling (SPP), and Non-Maximum Suppression (NMS) — using only C++11 and the cmath standard library.


Features

  • YOLOv5s-Ghost Architecture
    Implements a compact YOLOv5 variant with Ghost modules for reduced computational complexity.

  • 💻 Pure C++ Implementation
    Written entirely from scratch using standard C++11 and <cmath>. No OpenCV, PyTorch, or TensorFlow used.

  • 📦 Non-Maximum Suppression (NMS)
    Includes confidence thresholding (0.4) and IoU-based NMS (0.5) for output filtering.

  • 📚 COCO Class Support
    Supports 80 object categories including: person, car, dog, and more.

  • 🧩 Modular Design
    Separates neural network inference logic (my_top.cpp) from detection post-processing (tb.cpp).

  • 🧰 Makefile Included
    Simplifies compilation with g++ for CPU execution.


Prerequisites

  • C++11-compliant compiler (e.g., g++).
  • make utility for easy compilation.
  • Manually prepared image data (due to no external image libraries).
  • ImageData/255.

Getting Started

1️⃣ Clone the Repository

bash git clone https://github.com/engrbilal992/YOLOv5s-Ghost-Inference-in-Cpp-from-scratch.git cd YOLOv5s-Ghost-Inference-in-Cpp-from-scratch


2️⃣ Prepare Dependencies

Ensure the following header files are present in your project:

image.h, proto.h, headers.h, hardware_modules.h

These hold pre-trained weights, helper functions, and data structures for the model.


3️⃣ Build the Project

Compile using the Makefile:

bash make

This will generate an object_detection executable.


4️⃣ Run Inference

Run the detector:

bash ./object_detection

Input:
Modify tb.cpp to load or define a 640x640 RGB image as an array.

Output:
Results will print in this format:

xyxy: [x1, y1, x2, y2] conf: <confidence> cls: <class_name>

Example:

xyxy: [100.5, 150.2, 200.7, 250.9] conf: 0.85 cls: person xyxy: [300.1, 320.4, 400.2, 420.8] conf: 0.78 cls: car


5️⃣ Clean Up

Remove compiled binaries:

bash make clean


Project Structure

| File / Folder | Purpose | |---------------------------|--------------------------------------------------------------| | tb.cpp | Main file: post-processing and detection output. | | my_top.cpp | Neural network inference core. | | headers/ | Contains weights, utility functions, and data structures. | | Makefile | Compilation script for g++. |


Customization

  • Image Loading:
    You can write your own function in tb.cpp to load or define input images.

  • Threshold Adjustment:
    Modify conf_thres and iou_thres in tb.cpp to fine-tune detection sensitivity.

  • Model Weights:
    Replace kernel and bias arrays in headers.h to use your custom-trained YOLOv5s-Ghost weights.


Limitations

  • Image data must be provided as an array (no OpenCV or external libraries used).
  • Model weights are hardcoded in headers.h.
  • Focused on clarity and correctness rather than maximum runtime performance.

Acknowledgment

If you use this work in academic research, commercial projects, or any derivative work,
please give credit to the author:

Muhammad Bilal Sajid Email: bilalsajid695@gmail.com GitHub: https://github.com/engrbilal992/YOLOv5s-Ghost-Inference-in-Cpp-from-scratch Contact: +92 314 5844461

Your acknowledgment is genuinely appreciated!


Credits

Inspired by the YOLOv5 architecture and GhostNet for lightweight convolutional neural networks.
This project was created for educational and research purposes to showcase pure C++ object detection from scratch.


Owner

  • Name: Engr Muhammad Bilal
  • Login: engrbilal992
  • Kind: user
  • Location: Pakistan

Electronics Engineer, Skilled in Vivado, Vitis HLS, C/C++, Python, Verilog, and embedded systems.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software in your research, please cite it as below."
title: "YOLOv5s-Ghost Inference in C++ from Scratch"
authors:
  - family-names: Sajid
    given-names: Muhammad Bilal
    email: bilalsajid695@gmail.com
    orcid: https://orcid.org/0009-0005-7496-8545
    affiliation: "Independent Researcher"
date-released: 2025-04-18
url: "https://github.com/engrbilal992/YOLOv5s-Ghost-Inference-in-Cpp-from-scratch"
version: "1.0.0"
keywords:
  - YOLOv5
  - GhostNet
  - Object Detection
  - C++
  - Deep Learning
  - Inference
  - Computer Vision
  - Lightweight Model
abstract: >
  This repository provides a pure C++ implementation of YOLOv5s-Ghost, an efficient
  and lightweight object detection model based on the YOLOv5 architecture and Ghost modules.
  Designed without external dependencies, the implementation uses only standard C++11
  and cmath for inference on 640x640 RGB images. It outputs bounding boxes, confidence
  scores, and class predictions for 80 COCO categories. This project serves as an educational
  and research-friendly example of writing deep learning inference from scratch in C++.

GitHub Events

Total
  • Watch event: 2
  • Push event: 4
  • Create event: 2
Last Year
  • Watch event: 2
  • Push event: 4
  • Create event: 2