semvec/pypi-packages huggingface dataset:
pi-inference 0.1.0
pi-inference
Requires Python: >=3.8

<img src="https://github.com/ethanlee928/pi-inference/raw/main/images/raspberries-inference.jpg" width="75%" alt="raspberries-inference">

# pi-inference

A Computer Vision Inference Pipeline for Raspberry Pi inspired by [Jetson Inference](https://github.com/dusty-nv/jetson-inference).

The pipeline utilized `Gstreamer` and [`picamera2`](https://github.com/raspberrypi/picamera2) for video pipeline, and [`ncnn`](https://github.com/Tencent/ncnn) for optimized inference.

## 🖥️ Install

The pipeline is based on Gstreamer v1.22.0.

```bash
sudo scripts/install-packages.sh
```

Install the `pi-inference` package in a `Python>=3.8` environment.

```bash
pip install pi-inference
```

## 🚀 Quick Start

Inference using USB camera with pretrained `YOLOv8s` model, and display on GUI window.

```python
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`](examples).

## ⛏️ Development

Install the package using pip

```bash
# 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]"
```
fluent-simple-logger 0.1.10
A simple logger library for Python.
Requires Python: >=3.6

# Simple Logger

Simple Logger is a simple and customizable logging library for Python. It provides various logging levels with colored output for better visibility in the console and logs messages to a specified file.

## Features

- **Multiple Log Levels**: Log messages with different severity levels, including INFO, WARNING, ERROR, DEBUG, and CRITICAL.
- **Custom Prefix**: Easily customize the prefix for all log messages.
- **Colored Output**: Get colorful console output for better readability.
- **File Logging**: Automatically logs messages to a file with a timestamp.
- **Graceful Error Handling**: Stops execution on critical errors with a clear message.

## Installation

You can install the library using pip:

```bash
pip install fluent-simple-logger
```

## Usage

Here's a quick example of how to use Simple Logger:

```python
from simple_logger.logger import Logger

# Create a logger instance
logger = Logger()

# Log messages
logger.info("This is an informational message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.debug("This is a debug message.")
logger.critical("This is a critical error message.")
```

### Custom Prefix

You can customize the prefix used in log messages like this:

```python
logger.set_prefix("[Custom Prefix]")
logger.info("This is an info message with a custom prefix.")
```

### Logging to a Specific File
You can specify a different log file when creating the logger instance:

```python 
logger = Logger(log_file='custom_log.txt')
logger.info("This message will be logged to custom_log.txt.")
```

### Running Tests
To run the tests for the Simple Logger library, you can use the following command:
```bash
python -m unittest discover tests
```

### Contributing
Contributions are welcome! If you have suggestions for improvements or want to report a bug, please create an issue or submit a pull request.

### License 
This project is licensed under the MIT License.