BerryNet

DT42GPL-3.0活跃维护

在树莓派等边缘设备上跑深度学习推理的网关,把模型部署到 IoT 终端并通过 MQTT 上报结果,省去云端往返。

Deep learning gateway on Raspberry Pi and other edge devices

v3.10.2发布于 2021-02-07 04:54 UTC1,614star222fork同步于 2026-11-10 05:53 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/DT42/BerryNet.git
cd BerryNet
./configure
硬件要求按 README 说明

需要 Raspberry Pi 5 或 4(含 500/400 与 Compute Module 5/4),系统为 64 位 Raspberry Pi OS Bookworm 或 Trixie;输入可用树莓派摄像头模块、USB 摄像头或 IP 摄像头。README 未说明显存要求。

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把树莓派变成离线运行的深度学习边缘网关,本地完成图像视频推理

在树莓派等边缘设备上跑深度学习推理的网关,把模型部署到 IoT 终端并通过 MQTT 上报结果,省去云端往返。

核心能力

  • 用 MQTT 消息在组件间传递图像帧与推理结果
  • 提供 LiteRT 与 ONNX Runtime 两种 AI 引擎
  • 支持 MobileNet 分类与 SSD MobileNet、YOLO 检测
  • 用 bn_model 下载模型包并校验校验和
  • supervisor 管理相机、引擎、看板等组件

容易踩的坑

configure 会下载目标检测模型到 /usr/share/dlmodels,需联网;默认用 LiteRT,改用 ONNX Runtime 要设 BERRYNET_ENGINE=onnx 再执行 configure;Mosquitto 默认在 1883 端口无认证接受连接,不可信网络需加防火墙或认证。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v3.10.2
  1. v3.10.2最新正式版2021-02-07 · 2021-02-07 04:54 UTC

    这个版本没有写更新说明。

  2. v3.10.12020-11-01 · 2020-11-01 04:33 UTC
    查看更新说明

    Added

    • Get berrynet Python Wheel on PyPI
    • bndyda module is the interface to use a Dyda data pipeline as a single service / engine.
    • Experimental - dyda_config_update is the mockup to updae Dyda pipeline configuration remotely.

    Changed

    • Make camera and fbdashboard clients to be AIKEA-compatible w/o customization.
    • Docker support from Debian Stretch to Buster.

    Fixed

    • TFLite compatibility issue caused by v2.3.0 API changes.
    • OpenVINO compatibility issue caused by 2020.1 for x86 update.
  3. v3.7.0Release v3.7.02019-07-19 · 2019-07-19 10:48 UTC
    查看更新说明

    Installation image, md5sum, and installation guide:

    Features and Improvements

    1. Use TFLite as default engine
    2. Add bn_{tflite, openvino, darknet} CLI executors
    3. Update TFLite support to 1.14.0
    4. Update OpenVINO support to 2019R1.1

    Incompatible Changes

    N/A

  4. v3.5.1Release v3.5.12019-05-19 · 2019-05-19 09:31 UTC
    查看更新说明

    Installation image, md5sum, and installation guide:

    Features and Improvements

    1. Update Wiki pages
    2. Fix camera.py stream-src param issue
    3. Update default supervisor configuration file

    Incompatible Changes

    N/A

  5. v3.5.02019-05-19 · 2019-05-19 03:45 UTC
    查看更新说明

    Installation image, md5sum, and installation guide:

    • Generating and will update later.

    Features and Improvements

    1. Make camera.py to support video stream input.
    2. Push freeboard to Debian, and use the upstream version as the base of BerryNet dashboard.

    Incompatible Changes

    1. Freeboard configuration format is changed by upstream.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Docker Image CI

    Supporting BerryNet

    Introduction

    This project turns Raspberry Pi into an intelligent gateway with deep learning running on it. No internet connection is required, everything is done locally on the edge device itself. Further, multiple edge devices can create a distributed AIoT network.

    At DT42, we believe that bringing deep learning to edge devices is the trend towards the future. It not only saves costs of data transmission and storage but also makes devices able to respond according to the events shown in the images or videos without connecting to the cloud.

    Figure 1

    Figure 1 shows the software architecture of the project, we use Python, MQTT and AI engines to analyze images or video frames with deep learning. The AI engines run models with LiteRT or ONNX Runtime. There are two types of AI engines, the classification engine (with MobileNet [1] models) and the object detection engine (with SSD MobileNet [2] or Ultralytics YOLO such as YOLO26 [3] models).

    flowchart LR
        cameras["Raspberry Pi camera module<br/>USB camera<br/>IP camera"]
        sensors["Zigbee sensors"]
    
        subgraph rpi ["Raspberry Pi"]
            camera["bn_camera"]
            z2m["Zigbee2MQTT"]
            subgraph broker ["MQTT broker (Mosquitto)"]
                rgbimage>"berrynet/data/rgbimage"]
                result>"berrynet/engine/{service_name}/result"]
                zigbee>"zigbee2mqtt/{sensor}"]
                soilmoisture>"berrynet/data/soilmoisture"]
            end
            models[("Model packages<br/>bn_model")]
            engine["AI engine<br/>bn_litert: LiteRT<br/>bn_onnx: ONNX Runtime"]
            soil["bn_soil_monitor"]
            display["bn_dashboard"]
            collector["bn_data_collector"]
            notifier["bn_telegram<br/>bn_gmail"]
        end
    
        browser["Freeboard dashboard<br/>in browser"]
        messaging["Telegram<br/>Email"]
    
        cameras --> camera --> rgbimage --> engine --> result
        models --> engine
        result --> browser
        result --> display
        result --> collector
        result --> notifier --> messaging
        sensors --> z2m --> zigbee --> soil --> soilmoisture
        soil --> messaging
    

    Figure 2 shows how the components work together. They exchange data as MQTT messages, e.g. camera frames and inference results, through the Mosquitto broker on the Raspberry Pi, and supervisor manages them. Figure 3 shows the differences between classification and object detection.

    Figure 3

    One of the application of this intelligent gateway is to use the camera to monitor the place you care about. For example, Figure 4 shows the analyzed results from the camera hosted in the DT42 office. The frames were captured by the IP camera and they were submitted into the AI engine. The output from the AI engine will be shown in the dashboard. To get a notification when there is a dog coming into the meeting area, run the Telegram client bn_telegram or the email client bn_gmail with --target-label dog.

    Figure 4

    Supported Hardware

    • Raspberry Pi 5 or Raspberry Pi 4, including Raspberry Pi 500/400 and Compute Module 5/4
    • 64-bit Raspberry Pi OS Bookworm or Trixie
    • Raspberry Pi camera module, USB camera, or IP camera

    Installation

    Install BerryNet from source on Raspberry Pi OS:

    $ git clone https://github.com/DT42/BerryNet.git
    $ cd BerryNet
    $ ./configure
    

    configure installs BerryNet into /opt/berrynet/venv (the bn_* commands are linked to /usr/local/bin), downloads the object detection model into /usr/share/dlmodels, and starts the default application with supervisor. The default application runs LiteRT, run BERRYNET_ENGINE=onnx ./configure to use ONNX Runtime instead.

    You can also build and run a Docker image:

    $ docker build -t berrynet -f docker/Dockerfile .
    $ docker run -p 1883:1883 -p 3000:3000 -p 8080:8080 --device /dev/video0 berrynet
    

    AI Engines and Models

    BerryNet runs models with LiteRT (bn_litert) or ONNX Runtime (bn_onnx). bn_model downloads model packages and verifies their checksums:

    # Show model packages which can be installed
    $ bn_model available
    
    # Install an ONNX classification model
    $ sudo bn_model install mobilenet-v2-imagenet-onnx
    
    # Run engines with model packages
    $ bn_litert --service detector --model_package ssd-mobilenet-v1-coco-litert
    $ bn_onnx --service classifier --model_package mobilenet-v2-imagenet-onnx
    

    You can also give model and label files with --model and --label. An engine publishes results to the MQTT topic berrynet/engine/<service_name>/result, and the service name is <engine><service> by default, e.g. litertdetector or onnxclassifier.

    To detect objects with the latest Ultralytics YOLO, YOLO26, export it to LiteRT or ONNX with Ultralytics on a Linux x86 or macOS computer, and copy the model to Raspberry Pi:

    # On the computer
    $ pip install ultralytics
    $ yolo export model=yolo26n.pt format=litert nms=False
    $ yolo export model=yolo26n.pt format=onnx nms=False
    
    # On Raspberry Pi
    $ bn_litert --service yolo --model yolo26n.tflite
    $ bn_onnx --service yolo --model yolo26n.onnx
    

    nms=False exports the end-to-end YOLO26 model, which outputs detections without NMS and runs faster. The yolo engines read labels from the model, and also run models exported without nms=False, and YOLO11 or YOLOv8 models. Ultralytics YOLO models are licensed under AGPL-3.0.

    Development Environment

    The Python development environment is managed by uv and supports Python 3.11 or newer (tested up to 3.15).

    $ uv sync --all-extras
    
    # Download the models and images for the tests
    $ BERRYNET_MODEL_DIR=models uv run python -m tests.data
    
    $ BERRYNET_MODEL_DIR=models uv run python -m unittest
    

    LiteRT and ONNX Runtime do not publish wheels for Python 3.15 yet, so on Python 3.15 their extras install nothing and the engine tests are skipped.

    Start and Stop BerryNet

    BerryNet performs an AIoT application by connecting independent components together. Component types include but not limited to AI engine, I/O processor, data processor (algorithm), or data collector.

    We recommend to manage BerryNet componetns by supervisor, but you can also run BerryNet components manually. You can manage BerryNet via supervisorctl:

    ```
    # Check status of BerryNet components
    $ sudo supervisorctl status all
    
    # Stop Camera client
    $ sudo supervisorctl stop camera
    
    # Restart all components
    $ sudo supervisorctl restart all
    
    # Show last stderr logs of camera client
    $ sudo supervisorctl tail camera stderr
    ```
    

    For more possibilities of supervisorctl, please refer to the official tutorial.

    The default application has three components:

    • Camera client to provide input images
    • Object detection engine (LiteRT with SSD MobileNet) to find type and position of the detected objects in an image
    • Dashboard to display the detection results

    You will learn how to configure or change the components in the Configuration section.

    Dashboard: Freeboard

    Open Freeboard on RPi (with touch screen)

    Freeboard is a web-based dashboard. Here are the steps to show the detection result image and text on Freeboard:

    • 1: Enter http://127.0.0.1:8080/#source=dashboard-litertdetector.json in browser's URL bar, and press enter
    • 2: Wait for seconds, you should see the inference result image and text on Freeboard

    If the default application runs ONNX Runtime, use dashboard-onnxdetector.json instead of dashboard-litertdetector.json here and below.

    Open Freeboard on another computer

    Assuming that you have two devices:

    • Device A with IP 192.168.1.42, BerryNet default application runs on it
    • Device B with IP 192.168.1.43, you want to open Freeboard and see the detection result on it

    Here are the steps:

    • 1: Enter http://192.168.1.42:8080 in browser's URL bar, and press enter
    • 2: Download the Freeboard configuration for default application, dashboard-litertdetector.json
    • 3: Replace all the localhost to 192.168.1.42 in dashboard-litertdetector.json
    • 4: Click LOAD FREEBOARD, and select the modified dashboard-litertdetector.json
    • 5: Wait for seconds, you should see the inference result image and text on Freeboard

    For more details about dashboard configuration (e.g. how to add widgets), please refer to Freeboard project.

    Enable Data Collector

    You might want to store the snapshot and inference results for data analysis.

    To run BerryNet data collector manually, you can run the command below:

    $ bn_data_collector --topic-config <topic-config-filepath> --data-dirpath <result-dirpath>
    

    The topic config indicates what MQTT topic the data collector will listen, and what handler will be triggered. Here is a topic config example:

    {
        "berrynet/engine/litertdetector/result": "self.update"
    }
    

    The inference result image and text will be saved into the indicated result directory.

    Soil Moisture Monitor: Zigbee Sensors to Telegram

    BerryNet can also watch Zigbee soil moisture sensors (e.g. THIRDREALITY Smart Soil Moisture Sensor Gen2 with SONOFF ZBDongle-P) through Zigbee2MQTT, and send too dry/wet, low battery and offline alerts, scheduled reports and /status replies to Telegram:

    $ bn_soil_monitor --config /etc/berrynet/soil-monitor.json
    

    Please refer to the soil moisture monitor guide for the setup details.

    Configuration

    The default supervisor config is at /etc/supervisor/conf.d/berrynet-litert.conf, or berrynet-onnx.conf with BERRYNET_ENGINE=onnx. To write your own supervisor config, you can refer to here for more example supervisor configs of BerryNet

    The MQTT broker (Mosquitto) accepts clients without authentication on port 1883, and on port 3000 over websockets for the dashboard, so that BerryNet components on other devices can connect. On an untrusted network, restrict these ports with a firewall or set up Mosquitto authentication.

    Camera Client

    BerryNet camera client can run in two modes: stream or file. In stream mode, Raspberry Pi camera module, USB camera and IP camera can be supported, and input frame rate (FPS) can be changed on demand (default is 1). In file mode, user can indicate filepath as input source.

    To run camera client in stream mode:

    # USB camera /dev/video0
    $ bn_camera --fps 5
    
    # Raspberry Pi camera module, read through rpicam-vid
    $ bn_camera --stream-src picamera --fps 5
    
    # IP camera
    $ bn_camera --stream-src rtsp://<ip-address>/<stream-path> --fps 5
    

    configure uses the Raspberry Pi camera module in the default application if one is connected.

    To run camera client in file mode:

    $ bn_camera --mode file --filepath <image-filepath>
    

    Discussion

    Please use GitHub Discussions for questions, suggestions, or any idea discussion.