actpred: 两轮代码审计修复与文档合并
- 第 1 轮安全审计修复: F-1~F-10(路径校验、预训练架构修正等) - 第 2 轮复审修复 11 项: 3 项上轮修复不完整(R01 checkpoint 键校验/ R02 fused_hidden_dim 值域/R03 pretrained=False)+ 8 项新问题 (actions.npy 形状校验、帧数警告、CLI 值域校验、stats 形状与路径、 onnxscript 依赖、归一化语义、解析去重) - 单元测试由 17 扩展至 51 用例(50 通过 + 1 环境性跳过) - 审计文档两轮合并至 actpred_CODE_AUDIT_20260808.md,更新 INDEX
This commit is contained in:
1 parent
23a855963b
commit
63cfdd2066
15 files changed
+960
-65
No files matched your search
+9
-4
@@ -27,12 +27,15 @@ class SimpleCNN(nn.Module):
|
||||
|
||||
|
||||
class MobileNetEncoder(nn.Module):
|
||||
def __init__(self, feature_dim: int = 128):
|
||||
def __init__(self, feature_dim: int = 128, pretrained: bool = True):
|
||||
super().__init__()
|
||||
from torchvision.models import mobilenet_v2, MobileNet_V2_Weights
|
||||
weights = MobileNet_V2_Weights.DEFAULT if pretrained else None
|
||||
try:
|
||||
backbone = mobilenet_v2(weights=MobileNet_V2_Weights.DEFAULT)
|
||||
backbone = mobilenet_v2(weights=weights)
|
||||
except Exception as e:
|
||||
if not pretrained:
|
||||
raise RuntimeError("加载 MobileNetV2 架构失败") from e
|
||||
raise RuntimeError(
|
||||
"MobileNetV2 预训练权重下载失败,可能是网络受限。"
|
||||
"请在联网环境中预下载权重"
|
||||
@@ -94,10 +97,12 @@ class FusionHead(nn.Module):
|
||||
|
||||
|
||||
class ActionPredictor(nn.Module):
|
||||
def __init__(self, model_cfg: ModelConfig, data_cfg: DataConfig):
|
||||
def __init__(self, model_cfg: ModelConfig, data_cfg: DataConfig,
|
||||
pretrained: bool = True):
|
||||
super().__init__()
|
||||
if model_cfg.cnn_backbone == "mobilenet":
|
||||
self.image_encoder = MobileNetEncoder(model_cfg.cnn_feature_dim)
|
||||
self.image_encoder = MobileNetEncoder(
|
||||
model_cfg.cnn_feature_dim, pretrained=pretrained)
|
||||
else:
|
||||
self.image_encoder = SimpleCNN(model_cfg.cnn_feature_dim)
|
||||
|
||||
|
||||
Reference in new issue
Block a user