From 8af8dec1b01b044ea1be3226178d10db36a43e9c Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Thu, 13 Aug 2026 15:25:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(actpred):=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=9B=BE=E5=83=8F=E5=88=86=E8=BE=A8=E7=8E=87=E6=94=B9=E5=9B=9E?= =?UTF-8?q?=20640=C3=97480?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实机测速显示 1080p 采集的预处理缩放(约 45ms)主导端到端延迟 (测速报告 §6.1),640×480 下端到端 18.6ms,与 NPU/ORT 推理开销 更匹配。640×480 亦能被 16 整除,部署导出池化无损失。 已有 checkpoint 自带配置不受影响,仅改新训练默认值。 --- actpred/README.md | 6 +++--- actpred/config.py | 8 ++++---- actpred/dataset.py | 2 +- actpred/gen_calibration.py | 2 +- actpred/test_actpred.py | 4 ++-- .../actpred_inference_speed_benchmark_20260813.md | 14 +++++++------- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/actpred/README.md b/actpred/README.md index 48cadf6..4b4db3a 100644 --- a/actpred/README.md +++ b/actpred/README.md @@ -120,8 +120,8 @@ recorder.flush() | 参数 | 默认值 | 说明 | |------|--------|------| -| `--image-width` | 1920 | 图像缩放宽度 | -| `--image-height` | 1080 | 图像缩放高度 | +| `--image-width` | 640 | 图像缩放宽度 | +| `--image-height` | 480 | 图像缩放高度 | | `--action-dim` | 18 | 动作向量维度(对齐 bot4cj 18 列:10 舵机 + 2 云台 + 扬声器频率 + 延时 + 4 预留)| | `--history-len` | 5 | 历史动作窗口长度 | | `--frame-len` | 3 | 输入图像帧数(含当前帧,旧帧在前)| @@ -131,7 +131,7 @@ recorder.flush() | `--attn-layers` | 2 | TransformerEncoder 层数 | | `--epochs` | 100 | 训练轮数 | | `--lr` | 0.001 | 学习率 | -| `--batch-size` | 4 | 批次大小(默认分辨率 1920×1080 下 CPU/Pi 内存受限;小分辨率可调大) | +| `--batch-size` | 4 | 批次大小(默认分辨率 640×480;更高分辨率需调小,小分辨率可调大) | | `--normalize-actions` | False | 动作归一化(`--no-normalize-actions` 关闭) | | `--dropout` | 0.1 | Dropout 率 | | `--weight-decay` | 0.0001 | 权重衰减 | diff --git a/actpred/config.py b/actpred/config.py index fe5d782..3397ead 100644 --- a/actpred/config.py +++ b/actpred/config.py @@ -5,8 +5,8 @@ from typing import Optional @dataclass class DataConfig: - image_width: int = 1920 - image_height: int = 1080 + image_width: int = 640 + image_height: int = 480 action_dim: int = 18 history_len: int = 5 frame_len: int = 3 @@ -28,8 +28,8 @@ class ModelConfig: @dataclass class TrainConfig: - # 默认输入分辨率 1920×1080,batch=32 在 CPU/Pi 上内存不可行; - # 高分辨率训练取小 batch,小分辨率可用 --batch-size 调大 + # 默认输入分辨率 640×480(1080p 采集的预处理缩放在实机测速中主导 + # 端到端延迟,见测速报告 §6.1);更高分辨率训练时需调小 batch batch_size: int = 4 epochs: int = 100 lr: float = 1e-3 diff --git a/actpred/dataset.py b/actpred/dataset.py index 748fae6..b79ad16 100644 --- a/actpred/dataset.py +++ b/actpred/dataset.py @@ -16,7 +16,7 @@ def _natural_key(p): class ActionDataset(Dataset): def __init__(self, data_dir: str, history_len: int, action_dim: int, - image_width: int = 1920, image_height: int = 1080, + image_width: int = 640, image_height: int = 480, normalize_actions: bool = False, action_stats_path: str = None, episode_indices: list = None, frame_len: int = 3): diff --git a/actpred/gen_calibration.py b/actpred/gen_calibration.py index 9c54ae1..5472cb3 100644 --- a/actpred/gen_calibration.py +++ b/actpred/gen_calibration.py @@ -60,7 +60,7 @@ def build_image_samples(n_samples, frame_len, height, width, rng, """生成 (n_samples, frame_len, 3, H, W) uint8 校准图像 存 uint8 原始像素值(0~255),加载时再做 ToTensor+Normalize,节省磁盘。 - 经 memmap 分块填充后返回:1080p 默认分辨率下整块数组约 600MB, + 经 memmap 分块填充后返回:高分辨率(如 1080p)下整块数组可达 ~600MB, 一次性分配容易挤爆内存,分块写盘把峰值压到 chunk_samples 帧量级。 """ if chunk_samples < 1: diff --git a/actpred/test_actpred.py b/actpred/test_actpred.py index 41dac13..544d2fe 100644 --- a/actpred/test_actpred.py +++ b/actpred/test_actpred.py @@ -305,8 +305,8 @@ class TestConfig(unittest.TestCase): def test_default_config(self): cfg = Config() - self.assertEqual(cfg.data.image_width, 1920) - self.assertEqual(cfg.data.image_height, 1080) + self.assertEqual(cfg.data.image_width, 640) + self.assertEqual(cfg.data.image_height, 480) self.assertEqual(cfg.data.action_dim, 18) self.assertEqual(cfg.data.history_len, 5) self.assertEqual(cfg.data.frame_len, 3) diff --git a/docs/reports/actpred_inference_speed_benchmark_20260813.md b/docs/reports/actpred_inference_speed_benchmark_20260813.md index b7144fe..f2d82bf 100644 --- a/docs/reports/actpred_inference_speed_benchmark_20260813.md +++ b/docs/reports/actpred_inference_speed_benchmark_20260813.md @@ -4,15 +4,15 @@ 设备:Raspberry Pi 5(4×A76)+ AI HAT 2(Hailo-10H) 模型:actpred(~450K 参数,frame_len=3,history_len=5,action_dim=18) -> ⚠️ **基线分辨率说明(2026-08-12 补注,N-3 修复)** +> ⚠️ **基线分辨率说明(2026-08-13 更新)** > > 本报告 §1~§4 的全部数据均在 **640×480** 输入分辨率下测得。 -> 提交 `91b3004`(2026-08-12)已将模块默认输入分辨率改为 -> **1920×1080**(`config.py` 默认 `image_width/image_height`,与 pybot -> 相机采集分辨率对齐)。**推理延迟随输入像素量近似线性增长 -> (1920×1080 ≈ 640×480 的 6.75 倍像素),本报告数字不能直接外推到 -> 新默认分辨率。** x86 参考机上的 1920×1080 复测数据见 §5; -> Pi 5 / Hailo 板载在新分辨率下的数据待补测。 +> 提交 `91b3004`(2026-08-12)曾将模块默认输入分辨率改为 +> **1920×1080**(与 pybot 相机采集分辨率对齐);2026-08-13 实机测速 +> 发现 1080p 采集的预处理缩放(约 45ms)主导端到端延迟(§6.1), +> 默认分辨率**改回 640×480**(`config.py` 默认 +> `image_width/image_height`),§1~§4 数据重新适用。 +> 1920×1080 的 x86 复测数据见 §5,仅作分辨率影响趋势参考。 ## 1. 测试方法