pi-inference
Project description
pi-inference
A Computer Vision Inference Pipeline for Raspberry Pi inspired by Jetson Inference.
The pipeline utilized Gstreamer and picamera2 for video pipeline, and ncnn for optimized inference.
🖥️ Install
The pipeline is based on Gstreamer v1.22.0.
sudo scripts/install-packages.sh
Install the pi-inference package in a Python>=3.8 environment.
pip install pi-inference
🚀 Quick Start
Inference using USB camera with pretrained YOLOv8s model, and display on GUI window.
import logging
import supervision as sv
from ncnn.model_zoo import get_model
from pi_inference import VideoOutput, VideoSource
from pi_inference import functions as f
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s: %(message)s")
logger = logging.getLogger(__name__)
video_source = VideoSource("v4l2:///dev/video0", {"codec": "mjpg"})
video_output = VideoOutput("display://0", {})
net = get_model(
"yolov8s",
target_size=640,
prob_threshold=0.25,
nms_threshold=0.45,
num_threads=4,
use_gpu=False,
)
box_annotator = sv.BoxAnnotator()
labels_annotator = sv.LabelAnnotator()
fps_monitor = sv.FPSMonitor()
while True:
try:
frame = video_source.capture(timeout=300)
if frame is not None:
fps_monitor.tick()
detections = f.from_ncnn(frame, net)
labels = [
f"{class_name} {confidence:.2f}"
for class_name, confidence in zip(detections["class_name"], detections.confidence)
]
frame = box_annotator.annotate(scene=frame, detections=detections)
frame = labels_annotator.annotate(scene=frame, detections=detections, labels=labels)
frame = f.draw_clock(frame)
frame = f.draw_text(frame, f"FPS: {fps_monitor.fps:.1f}", anchor_y=80)
video_output.render(frame)
except KeyboardInterrupt:
break
video_source.on_terminate()
video_output.on_terminate()
Find out more in examples.
⛏️ Development
Install the package using pip
# For raspberrypi
python3 -m venv --system-site-packages .venv
# For others
python3 -m venv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install -e ".[dev]"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pi_inference-0.1.0.tar.gz.
File metadata
- Download URL: pi_inference-0.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.31.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a29ffd51086f81562280b188762a86f805863b0701b0adf12a92284e3da1f83
|
|
| MD5 |
c3f05bc5b2786973b0bde6a5456eaf11
|
|
| BLAKE2b-256 |
cc062c4ea6fb1083982cfc103f0594dbabf77a9f8002d1db71146be09297c9e0
|
File details
Details for the file pi_inference-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pi_inference-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.31.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
580cd6af4e04da42104eb53c7e1360a03277429f651e52019180ed4fc38b6416
|
|
| MD5 |
fca4568208543d06a56890e3b0e90dd8
|
|
| BLAKE2b-256 |
d80d9d84d082438267168cf8aaaa50d0663223b9df1d65a0c2baa34b29fa4f20
|