Files
ModelTrainEval/figures/simclr-contrastive.mmd
Shaun ZhouandClaude Opus 5 4fc0fa5353 docs: 无监督聚类的数学说明、mermaid 图与 README
- docs/unsupervised-clustering.md: 逐图标准化对仿射光照群的不变性证明、
  多 stage 特征的取舍、PCA 白化失效的谱分析、KMeans 收敛性与 kmeans++ 近似比、
  轮廓系数与 NMI 稳定性的定义、NT-Xent 与 InfoNCE 下界,附全部消融数据与代码对照表
- figures/: 四张 mermaid 图(流水线、KMeans 控制流、SimCLR、主成分谱),
  含 .mmd 源、.md 预览与渲染好的 .png
- README: 数据准备、训练评估、多类/单类、SwanLab、Profiler、聚类与自监督的运行说明

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 17:55:48 +08:00

50 lines
2.2 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
flowchart TB
classDef data fill:#D1FAE5,stroke:#10B981,stroke-width:2px,color:#064E3B
classDef aug fill:#DBEAFE,stroke:#2563EB,stroke-width:2px,color:#1E3A8A
classDef net fill:#EDE9FE,stroke:#7C3AED,stroke-width:2px,color:#4C1D95
classDef loss fill:#FFEDD5,stroke:#EA580C,stroke-width:2px,color:#7C2D12
classDef note fill:#FEF3C7,stroke:#D97706,stroke-width:2px,color:#78350F
batch["一个 batch:B 张无标注图 { Iᵢ }, i = 1…B"]:::data
aug["随机增强分布 𝒯:RandomResizedCrop 0.5~1.0 · 水平/垂直翻转 · 高斯模糊<br/>对每张图独立采样两次 t, t′ ~ 𝒯"]:::aug
v1["视图 1&nbsp;&nbsp; x⁽¹⁾ᵢ = t(Iᵢ)"]:::aug
v2["视图 2&nbsp;&nbsp; x⁽²⁾ᵢ = t′(Iᵢ)"]:::aug
bb1["卷积骨架 f_θ"]:::net
bb2["卷积骨架 f_θ&nbsp;&nbsp;(共享同一份参数)"]:::net
h1["h⁽¹⁾ᵢ = f_θ(x⁽¹⁾ᵢ) ∈ ℝᴰ"]:::net
h2["h⁽²⁾ᵢ = f_θ(x⁽²⁾ᵢ) ∈ ℝᴰ"]:::net
g1["投影头 g_φ<br/>Linear → BN → ReLU → Linear"]:::net
g2["投影头 g_φ&nbsp;&nbsp;(共享参数)"]:::net
z1["z⁽¹⁾ᵢ = g_φ(h⁽¹⁾ᵢ) ∈ ℝ¹²⁸"]:::net
z2["z⁽²⁾ᵢ = g_φ(h⁽²⁾ᵢ) ∈ ℝ¹²⁸"]:::net
sim["ℓ₂ 归一化后拼成 Z ∈ ℝ²ᴮˣ¹²⁸<br/>相似度矩阵 S = ZZᵀ / τ ∈ ℝ²ᴮˣ²ᴮ,τ = 0.2<br/>对角线置 −∞,排除自己和自己"]:::loss
nt["NT-Xent 损失<br/>ℒ = − (1/2B) Σₖ log [ exp(S_{k,π(k)}) / Σ_{m≠k} exp(S_{k,m}) ]<br/>π(k):同一张图的另一个视图"]:::loss
pos["分子 = 正样本对(1 个)<br/>同图另一视图 π(k)"]:::note
neg["分母 = 全部 2B−2 个负样本<br/>batch 内其他所有视图"]:::note
step["反向传播同时更新 θ 与 φ<br/>AdamW + cosine,AMP"]:::loss
ckpt["训练收敛后只保存骨架<br/>simclr_backbone.pth<br/>投影头 g_φ 丢弃"]:::data
use["聚类阶段用 h = f_θ(x),不用 z<br/>投影头会滤掉对比任务用不上、<br/>但下游有用的信息"]:::note
batch --> aug
aug --> v1
aug --> v2
v1 --> bb1 --> h1 --> g1 --> z1
v2 --> bb2 --> h2 --> g2 --> z2
z1 --> sim
z2 --> sim
pos -.-> nt
neg -.-> nt
sim --> nt --> step --> ckpt --> use