Files
ModelTrainEval/utils/__init__.py
T
Shaun ZhouandClaude Opus 5 86c86b105c refactor: 按实际的五步工作流裁掉无关代码
实际工作流是:simclr 训练 -> 聚类 -> 人工归类 -> 分类训练 -> GradCAM/SHAP 生成
热力图与 box。据此移除不参与其中的检测/定位链路,共 31 个文件、约 2600 行:

- 模型:defect_net、postprocess、necks/、heads/center_head
- 数据:film_defect(YOLO 读取端)、target_encoder
- 引擎:trainer、evaluator、losses
- 入口:train.py、eval.py
- 脚本:convert_annotations、split_dataset、export_onnx、profile_inference
- 配置:configs/{train,eval,model,dataset}
- utils/labels(多类/单类标签模式,仅检测分类头使用)

共享模块按实际用量瘦身:engine/metrics 只留 AverageMeter(检测指标随之移除);
datasets/yolo 只留写出侧(IMAGE_SUFFIXES 与 write_data_yaml)——第 5 步产出的
YOLO 标签是给外部检测训练用的交换格式,读取端不再需要。

裁剪过程中修掉一个真 bug:generate_boxes 的 --stage 默认 6(layer3)对 tiny_conv
这类非 nn.Sequential 骨架直接抛异常。现在自动退回骨架最终输出并警告,
另加 --stage -1 显式选择最终输出。

五步工作流已端到端实跑验证(simclr 1 轮 -> 聚类 -> 导出 -> 分类 1 轮 ->
gradcam 与 shap 两种方法各生成一遍)。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 10:27:20 +08:00

32 lines
714 B
Python

"""通用工具:配置、注册表、日志、随机种子、设备检查。"""
from utils.config import Config, load_config
from utils.device import (
DeviceNotAvailableError,
PeakMemory,
available_backends,
describe_device,
memory_stats,
resolve_amp,
resolve_device,
)
from utils.logging import get_logger, setup_logging
from utils.registry import Registry
from utils.seed import seed_everything
__all__ = [
"Config",
"load_config",
"resolve_device",
"resolve_amp",
"describe_device",
"available_backends",
"memory_stats",
"PeakMemory",
"DeviceNotAvailableError",
"get_logger",
"setup_logging",
"Registry",
"seed_everything",
]