feat(actpred): log_range 归一化——spk 两列对数尺度修正精度错配
fixed_range 线性 min-max 下常用值挤在低端(10Hz→0.002),闭环反馈 中小绝对误差=大相对误差(模型 C/D 发散根因)。新增 normalize_mode= log_range:spk.F/spk.delay 用 log10(1+x) 对数尺度(10Hz→0.27), 舵机列保持线性。全链路接入(dataset/pretrain/predict/onnx/hailo/ calibration/export),与 v3 审计 none 模式/元数据自动识别合并。
This commit is contained in:
1 parent
fc310c9081
commit
1cf428f384
11 files changed
+306
-66
No files matched your search
+10
-7
@@ -11,7 +11,7 @@ from torchvision import transforms
|
||||
from torchvision.transforms import functional as TF
|
||||
|
||||
from imu_norm import imu_scales
|
||||
from action_norm import normalize_action
|
||||
from action_norm import normalize_action, is_range_mode
|
||||
|
||||
|
||||
def _natural_key(p):
|
||||
@@ -29,8 +29,11 @@ class ActionDataset(Dataset):
|
||||
imu_dim: int = 0, normalize_mode: str = "zscore"):
|
||||
self.history_len = history_len
|
||||
self.action_dim = action_dim
|
||||
# 固定物理范围归一化(免 stats 文件);仅 normalize_actions=True 生效
|
||||
self._fixed_range = normalize_actions and normalize_mode == "fixed_range"
|
||||
# 固定范围类归一化(fixed_range / log_range,免 stats 文件);
|
||||
# 仅 normalize_actions=True 生效
|
||||
self._range_mode = (normalize_mode
|
||||
if (normalize_actions and is_range_mode(normalize_mode))
|
||||
else None)
|
||||
# R2 方案一:>0 时样本带 "imu" 键(归一化姿态向量,缺失 episode 补零)
|
||||
self.imu_dim = imu_dim
|
||||
self.image_width = image_width
|
||||
@@ -87,7 +90,7 @@ class ActionDataset(Dataset):
|
||||
|
||||
self._action_mean = None
|
||||
self._action_std = None
|
||||
if normalize_actions and not self._fixed_range:
|
||||
if normalize_actions and not self._range_mode:
|
||||
if action_stats_path:
|
||||
if not os.path.exists(action_stats_path):
|
||||
raise FileNotFoundError(
|
||||
@@ -119,11 +122,11 @@ class ActionDataset(Dataset):
|
||||
def _norm(self, a):
|
||||
"""动作归一化(numpy → torch 前在 numpy 空间做,保持 float32)
|
||||
|
||||
fixed_range:固定物理范围 min-max → [0,1](clamp 防御,免 stats);
|
||||
fixed_range / log_range:固定物理范围 → [0,1](clamp 防御,免 stats);
|
||||
否则 z-score(_action_mean 为 None 时直通原始值)。
|
||||
"""
|
||||
if self._fixed_range:
|
||||
return normalize_action(a, self.action_dim)
|
||||
if self._range_mode:
|
||||
return normalize_action(a, self.action_dim, mode=self._range_mode)
|
||||
if self._action_mean is None:
|
||||
return a
|
||||
return (a - self._action_mean) / self._action_std
|
||||
|
||||
Reference in new issue
Block a user