ei-firmware-raspberry-pi-python
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEdge Impulse Python on Raspberry Pi
Raspberry Pi 上的 Edge Impulse Python
Use the official package with a Linux EIM executable built for the Pi's architecture. Do not pass an Arduino library, raw TFLite file, or EIM built for another architecture.
edge_impulse_linux使用官方的 包,并确保 Linux EIM 可执行文件是为 Pi 的架构构建的。不要传入 Arduino 库、原始 TFLite 文件,或为其他架构构建的 EIM。
edge_impulse_linuxSet up
设置
For Raspberry Pi OS:
bash
sudo apt install libatlas-base-dev libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
python3 -m pip install edge_impulse_linux pyaudio
chmod +x model.eimKeep dependencies in the project's virtual environment when possible. Verify the microphone with ALSA tools before debugging Python.
对于 Raspberry Pi OS:
bash
sudo apt install libatlas-base-dev libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
python3 -m pip install edge_impulse_linux pyaudio
chmod +x model.eim尽可能将依赖项保留在项目的虚拟环境中。调试 Python 之前,请使用 ALSA 工具验证麦克风。
Choose the runner
选择 Runner
- Use for custom numeric data, images, and general models.
ImpulseRunner - Use for streaming audio and keyword spotting.
AudioImpulseRunner - Use the official SDK image examples as the starting point for camera color conversion, resizing, and feature packing.
Always initialize the runner, inspect , and close it in or a context manager. Model metadata is the source of truth for frequency, frame size, labels, and input shape.
model_infofinally- 对于自定义数值数据、图像和通用模型,使用 。
ImpulseRunner - 对于流式音频和关键词识别,使用 。
AudioImpulseRunner - 以官方 SDK 图像示例为起点,完成摄像头颜色转换、图像缩放和特征打包。
始终初始化 Runner,检查 ,并在 或上下文管理器中将其关闭。模型元数据是采样频率、帧大小、标签和输入形状的权威依据。
model_infofinallyGeneral runner pattern
通用 Runner 模式
python
from edge_impulse_linux.runner import ImpulseRunner
runner = ImpulseRunner("model.eim")
try:
model_info = runner.init()
# Build one feature window in the exact training order and units.
features = []
result = runner.classify(features)
print(result["result"])
finally:
runner.stop()Check the installed SDK version's method signatures before finalizing code. The SDK and examples are canonical when an API differs from this pattern.
python
from edge_impulse_linux.runner import ImpulseRunner
runner = ImpulseRunner("model.eim")
try:
model_info = runner.init()
# Build one feature window in the exact training order and units.
features = []
result = runner.classify(features)
print(result["result"])
finally:
runner.stop()完成代码前,请检查已安装 SDK 版本的方法签名。如果 API 与此模式存在差异,应以 SDK 和官方示例为准。
USB microphone workflow
USB 麦克风工作流
- Enumerate PyAudio devices and select the intended input device explicitly.
- Read the model frequency and window requirements from .
model_info - Configure mono PCM with the required sample rate; convert samples exactly as the SDK example expects.
- Use to maintain the rolling audio window and continuous classifier state.
AudioImpulseRunner - Handle input overflow by fixing buffering or device configuration, not by silently discarding arbitrary chunks.
- Separate inference callbacks from slow network, UI, or file work so audio capture remains timely.
Do not resample unless necessary. If resampling is required, use a deterministic library and verify its output rate and dtype.
- 枚举 PyAudio 设备,并明确选择目标输入设备。
- 从 中读取模型所需的采样频率和窗口要求。
model_info - 按照所需采样率配置单声道 PCM;严格按照 SDK 示例要求转换采样数据。
- 使用 维护滚动音频窗口和持续运行的分类器状态。
AudioImpulseRunner - 通过修复缓冲机制或设备配置来处理输入溢出,不要静默丢弃任意数据块。
- 将推理回调与耗时的网络、UI 或文件操作分离,确保音频采集保持及时。
除非确有必要,否则不要进行重采样。如果必须重采样,请使用确定性库,并验证其输出采样率和 dtype。
Results
结果
Support the model's actual output:
- Classification and keyword spotting: inspect label scores and apply a user-defined threshold and debounce/cooldown policy.
- Object detection: iterate nonzero bounding boxes.
- Anomaly: report the anomaly score when present.
Do not assume scores sum to one for every model type.
支持模型的实际输出:
- 分类和关键词识别:检查标签分数,并应用用户定义的阈值以及防抖或冷却策略。
- 目标检测:遍历非零边界框。
- 异常检测:如果存在异常分数,则报告该分数。
不要假定所有模型类型的分数总和都等于一。
Troubleshoot
故障排查
- Use to surface EIM logs.
runner.init(debug=True) - For very large models, increase the timeout deliberately.
ImpulseRunner(..., timeout=SECONDS) - If initialization fails, verify executable permission, CPU architecture, deployment target, and shared-library dependencies.
- If predictions differ from Studio, compare one identical raw feature window before debugging live capture.
- For audio errors, verify ALSA/PulseAudio/PipeWire routing, sample format, channels, rate, and device ownership.
- 使用 显示 EIM 日志。
runner.init(debug=True) - 对于非常大的模型,应有意识地增大 的超时时间。
ImpulseRunner(..., timeout=SECONDS) - 如果初始化失败,请验证可执行权限、CPU 架构、部署目标以及共享库依赖项。
- 如果预测结果与 Studio 不一致,请先对比同一个原始特征窗口,再调试实时采集。
- 对于音频错误,请验证 ALSA、PulseAudio、PipeWire 的路由,以及采样格式、声道数、采样率和设备所有权。
Verify
验证
- Run a known Studio sample through the local pipeline.
- Compare the scores and preprocessing assumptions.
- Exercise continuous capture for several minutes while checking memory, latency, dropped frames, and clean shutdown.
- 通过本地流水线运行一个已知的 Studio 样本。
- 比较分数和预处理假设。
- 持续采集数分钟,同时检查内存、延迟、丢帧以及是否能够正常关闭。
Documentation
文档
- https://docs.edgeimpulse.com/tools/libraries/sdks/inference/linux/python — Linux Python SDK
- https://docs.edgeimpulse.com/hardware/deployments/run-linux-eim — Linux EIM deployment
- https://docs.edgeimpulse.com/tools/clis/edge-impulse-linux-cli — Edge Impulse Linux CLI
- https://docs.edgeimpulse.com/tools/libraries/sdks/inference/linux/python — Linux Python SDK
- https://docs.edgeimpulse.com/hardware/deployments/run-linux-eim — Linux EIM 部署
- https://docs.edgeimpulse.com/tools/clis/edge-impulse-linux-cli — Edge Impulse Linux CLI
Reference repositories
参考仓库
- https://github.com/edgeimpulse/linux-sdk-python — source of and the canonical runner examples
edge_impulse_linux - https://github.com/edgeimpulse/edge-impulse-linux-cli — Linux CLI used to download and run EIM models
- https://github.com/edgeimpulse/example-multi-impulse-python — Flask app running multiple impulses (object detection and visual anomaly detection)
- https://github.com/edgeimpulse/example-active-learning-linux-python-sdk — active-learning workflow with the Linux Python SDK
- https://github.com/edgeimpulse/linux-sdk-python — 的源代码及权威 Runner 示例
edge_impulse_linux - https://github.com/edgeimpulse/edge-impulse-linux-cli — 用于下载和运行 EIM 模型的 Linux CLI
- https://github.com/edgeimpulse/example-multi-impulse-python — 运行多个 Impulse 的 Flask 应用(目标检测和视觉异常检测)
- https://github.com/edgeimpulse/example-active-learning-linux-python-sdk — 使用 Linux Python SDK 的主动学习工作流