Skip to main content

speck_tools

用于 Speck 实验代码的 Python 工具库。所有工具通过一个入口导入:

from speck_tools import (
    ChannelHelper,
    generate_speck_config_c,
    generate_speck_config_c_spi,
    generate_flow_decode_comment,
    write_events_to_csv,
)

本版本整理已有代码并完善注释,保留原函数名、参数、默认值及配置字节编码。 暂不包含可视化工具,不需要 Matplotlib 或 samnagui。

安装

需要 Python 3.10 或更高版本,基础依赖为 NumPy。 PyPI 发布完成后,可直接安装公开发行包:

python -m pip install speck_tools

指定版本安装使用 python -m pip install speck_tools==0.1.1。 已安装的版本可通过 speck_tools.__version__ 查看。

也支持直接从源码仓库安装。仓库当前为私有仓库,需要先配置具有仓库读取权限的 GitHub SSH 身份:

python -m pip install "speck_tools @ git+ssh://git@github.com/Synsense-Industrial-Applications/speck_tools.git@main"

正式实验应将 @main 替换为经过验证的完整 commit SHA,记录在项目的 requirements.txt 中。维护者发布版本标签后,也可使用 @v0.1.0 这样的标签。 工具包版本保存在 src/speck_tools/_version.py。

也可以下载源码后安装:

git clone git@github.com:Synsense-Industrial-Applications/speck_tools.git
cd speck_tools
python -m pip install .

维护工具源码时使用 python -m pip install -e .。 源码提交、Git 版本标签和 PyPI 发行是三个步骤;以实际 PyPI 项目页面为准。 维护者首次发布前必须完成 PyPI 发布者绑定。

目录

src/speck_tools/
├── __init__.py          # 统一公开入口
├── _version.py          # 工具包版本
├── channel_mapping.py   # ChannelHelper、point_withchannel
├── config_export.py     # 两种配置编码和 C 文件导出
├── flow_decode.py       # 当前四方向光流的解码示例注释
└── event_io.py          # CSV 读写侧的存储、后台写入和事件计数

event_io 当前提供写入功能,没有新增 CSV 读取器。 算法网络配置和实验生成的 .c 应保存在使用者的项目中。

通道和空间映射

from speck_tools import ChannelHelper

helper = ChannelHelper(input_channel=2, input_size=128, output_size=64)
coarse = helper.get_tuple((1, 5, 6))  # (6, 2, 3)
assert helper.get_tuple(coarse, mode_flage=1) == (1, 5, 6)
padding, stride, kernel_size, weights = helper.generate_conv_mapping()

历史参数 mode_flage、方法 caculate_cxy 和类 point_withchannel 保持原拼写,避免已有代码失效。详细返回值和适用范围见函数 docstring。

配置导出

两种工具导出相同类型的 C 字节数组封装,但其内部固件协议不同:

接口 数据来源 是否需要开发板 配置协议
generate_speck_config_c 354 KiB Flash 镜像 否 legacy_flash
generate_speck_config_c_spi SDK 实际发送的 SPI 数据 是 spi_zero_rle

工具包升级后仍可生成旧协议,协议不随包版本自动切换。 samna 由硬件环境单独安装和管理;导入基础工具不加载 samna。 旧格式导出在调用时才导入 samna,SPI 捕获需要设备支持 make_unifirm_hook()。

from speck_tools import generate_speck_config_c

# config 是调用者已构造完成的 Speck2f 网络配置。
path = generate_speck_config_c(
    config, "output/model_legacy.c", fast_output=True,
)

完整参数、fast 输出说明、光流注释开关及 SPI 捕获示例见 配置导出说明。

事件存储

from speck_tools import write_events_to_csv, print_layer_feature_counts

# events 是已经从设备缓冲区读取到的同一批事件。
write_events_to_csv(events, "recordings/run_001")
print_layer_feature_counts(events)

每个物理 layer 对应 layer_<编号>.csv,列顺序保留为 feature,y,x,timestamp。后台进程写入和清理目录接口见 API 说明。

迁移现有项目

  1. 安装本库并固定版本或提交。
  2. 将旧项目中的 speck_tools.py 移出模块搜索路径,避免遮蔽已安装的包。
  3. 将独立文件导入改为 from speck_tools import ...。
  4. 使用同一份配置检查生成数组一致,再切换正式实验。

本次迁移不改动使用者已有算法脚本,也不自动修改 samna 环境。

测试与构建

python -m pip install -e .
python -m unittest discover -s tests -v
python -m pip install build
python -m build

dist/ 生成 wheel 和源码压缩包;安装 wheel 时,NumPy 必须已存在或能从 配置的软件源下载。CI 在 Python 3.10 和 3.12 中执行无板测试并验证 wheel 安装。 SPI 测试使用模拟设备,不会访问或修改硬件;实际 MCU 加载需在配套固件上验证。 初始代码迁移和七序列配置的一致性结果见 迁移验证记录。

版本维护

修改后运行回归测试,在 _version.py 和 CHANGELOG.md 中更新版本, 提交后再创建对应标签。涉及配置协议的修改必须明确记录,不能将工具包版本 当成 MCU 协议版本。发布流程见 维护说明。

Metadata

Release files for speck-tools 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for speck-tools 0.1.1
File Size Uploaded Provenance
speck_tools-0.1.1.tar.gz 32.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for speck-tools 0.1.1
File Interpreter ABI Platform
speck_tools-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 51.9 kB

Release files / speck_tools-0.1.1.tar.gz

Download URL speck_tools-0.1.1.tar.gz
Size 32.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8a018ab0abae4310efc3b2500efb0bb462910d4373eb53250ef261da249e38b0
BLAKE2b-256 checksum
How to use checksums
8afaab026be2364dceefb1415f6173505084f031c58998c3b5cb6dfee02ec294
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / speck_tools-0.1.1-py3-none-any.whl

Download URL speck_tools-0.1.1-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1097e08fbe6b1c77f8a0f1bacbd41a6486da319c624cd3ec3f90fb426430f88c
BLAKE2b-256 checksum
How to use checksums
5018757d162b21b6e59d1f5cad985c7b0327d79825362b08289212d700e696ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Security for speck-tools 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page