Deploying MobileNet SSD COCO Pretrained Model on
Raspberry Pi
Object detection with labels using Python and OpenCV DNN
Report Type: Practical implementation guide
Platform: Raspberry Pi with camera input
Model: MobileNet SSD trained on COCO classes
Purpose: Detect objects in real time and display labels and confidence
Raspberry Pi object detection report
1. Introduction
MobileNet SSD is a lightweight detector that works well on Raspberry Pi because it balances speed and
accuracy. SSD finds object boxes and classes in one pass, while MobileNet keeps the computation small.
This report shows how to run Python with OpenCV DNN to load a pretrained MobileNet SSD model, read
frames from a camera, detect objects, draw bounding boxes, and display label names with confidence scores.
The example uses COCO-style labels such as person, car, dog, bottle, and chair. The label list must match
the model files you download.
2. Required Hardware and Software
Raspberry Pi 3, 4, or 5 with Raspberry Pi OS installed
USB webcam or Raspberry Pi Camera Module
MicroSD card with at least 8 GB free space
Internet connection for installation and model download
Python 3, pip, NumPy, and OpenCV with DNN support
3. How the system works
The camera provides frames to Python.
OpenCV converts each frame into a blob.
The network returns detections with class IDs and confidence values.
Only detections above the chosen threshold are kept.
The program draws a box and writes the object label near it.
Raspberry Pi object detection report
4. Installation Commands
Run the following commands in the Raspberry Pi terminal. They install the required packages and tools for
the project.
If OpenCV is already installed on your system, keep the missing packages only.
sudo apt update
sudo apt upgrade -y
sudo apt install -y python3-pip python3-opencv libatlas-base-dev
pip3 install numpy
Create a working folder:
mkdir -p ~/mobilenet_ssd_pi
cd ~/mobilenet_ssd_pi
Download the model files and keep them in the same folder as the script.
# Required model files
# [Link]
# mobilenet_iter_73000.caffemodel
Create or copy the COCO label file in the same folder. Each line should contain one class name.
5. Important setup notes
Use a confidence threshold such as 0.5 to ignore weak detections.
Lower the resolution to 320x240 or 640x480 for better speed on older boards.
A USB webcam is usually the easiest camera for first testing.
Rotate or flip frames first if the camera image is upside down or mirrored.
Raspberry Pi object detection report
6. Working Python Code
Save the following code as detect_objects.py. It loads the pretrained model, detects objects, and displays
labels on the video frame.
The code uses a COCO label list. Replace it only if your model uses different labels.
import cv2
import numpy as np
PROTO = "[Link]"
MODEL = "mobilenet_iter_73000.caffemodel"
CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle",
"bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse",
"motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
net = [Link](PROTO, MODEL)
cap = [Link](0)
if not [Link]():
print("Error: Could not open camera.")
raise SystemExit
THRESHOLD = 0.5
while True:
ret, frame = [Link]()
if not ret:
print("Error: Could not read frame.")
break
h, w = [Link][:2]
blob = [Link]([Link](frame, (300, 300)), 0.007843, (300, 300), 127.5)
[Link](blob)
detections = [Link]()
for i in range([Link][2]):
confidence = detections[0, 0, i, 2]
if confidence > THRESHOLD:
idx = int(detections[0, 0, i, 1])
box = detections[0, 0, i, 3:7] * [Link]([w, h, w, h])
startX, startY, endX, endY = [Link]("int")
label = CLASSES[idx] if idx < len(CLASSES) else f"class_{idx}"
text = f"{label}: {confidence * 100:.1f}%"
[Link](frame, (startX, startY), (endX, endY), (0, 255, 0), 2)
y = startY - 15 if startY - 15 > 15 else startY + 15
[Link](frame, text, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
print(text)
[Link]("MobileNet SSD Detection", frame)
if [Link](1) & 0xFF == ord('q'):
break
[Link]()
[Link]()
7. Run command
python3 detect_objects.py
Raspberry Pi object detection report
8. Output and expected behavior
When the program runs, a window opens with the live camera feed. Any recognized object is surrounded by a
green box, and the label plus confidence score appears beside it. The terminal also prints the detected
names.
Example output: person: 98.4%, car: 91.2%, bottle: 67.8%.
9. Key points to remember
MobileNet SSD is lightweight, so it is suitable for real-time or near real-time detection on Raspberry Pi.
The model and label list must match.
Use lower resolution and close background apps for better speed.
Adjust the confidence threshold depending on how strict you want detections to be.
Press q to exit the camera window cleanly.
10. Conclusion
This setup provides a simple object-detection pipeline for Raspberry Pi using a pretrained MobileNet SSD
model. It can be extended later with image saving, video recording, GPIO actions, or a remote dashboard.
Raspberry Pi object detection report