将生成潜变量做最近邻时空扩展,再用块内负相关高斯噪声及式20系数组合,修正金字塔阶段跃迁中的噪声协方差。模块在训练与评估中均随机采样。
(2,3,4,3,5),spatial_factor=2、sigma_start=0.5;时空模式另传 temporal_indices=[0,2]。(2,3,4,6,10);target_time=3 模式 (2,3,3,6,10),根钩子均已实跑。0;噪声在 float32 中采样再转换 latent dtype;n=r² 或 r²·Tout,要求 n>1。forward() 数据流顺序拆解 · 点击任意子模块方块可同步查看对应源码切片空间路径保留4个时间片,把每个3×5网格扩展为6×10。时空路径先为每个样本选择一个粗时间片,再扩展为3×6×10。两种路径都采样等相关块噪声并与扩展 latent 组合,forward_hook 分别核对输出。
235 latents=rearrange(latents,'b c t h w -> (b t) c h w')236 latents=F.interpolate(latents,size=(height,width),mode='nearest')237 latents=rearrange(latents,'(b t) c h w -> b c t h w',b=batch,t=time)241 latents=latents[torch.arange(batch,device=latents.device),:,temporal_indices,:,:].unsqueeze(2)243 latents=F.interpolate(latents,size=(time,height,width),mode='nearest')244 n=r*r if keep_scale else r*r*time249 s=e/(e+math.sqrt(n)*(1-e))250 alpha=(1-s)*math.sqrt((n-1)/n)251 scale=((1-s)+s*math.sqrt(n))/math.sqrt(n)252 noise=self.sample_block_noise(batch,channels,time,height,width,n,block_number,keep_scale,r,self.eps,latents.device)253 return scale*latents+alpha*noise.to(latents)
示例 latents=(B,C,T,H,W),temporal_indices 为每个样本的 long 时间索引。仅空间上采样时省略 target_time 和 temporal_indices。
from SPFNoiseCorrectedUpsampler import SPFNoiseCorrectedUpsampler transition = SPFNoiseCorrectedUpsampler(2, target_time=3, sigma_start=0.5) y = transition(latents, temporal_indices)
Method 动机参考:生成式金字塔切换分辨率时,直接复制潜变量会改变噪声相关性;此算子显式加入协方差修正,适合宿主流匹配生成过程的阶段转换。
| 消融变体 | 结构配置 | 验证目的 |
|---|---|---|
| nearest 跃迁 | 仅最近邻扩展 | 比较复制后协方差与宿主生成指标 |
| 独立噪声对照 | 相同系数,改用 iid 高斯 | 区分噪声幅度与块负相关结构 |
| 完整修正 | nearest + 等相关块噪声 + 式20 | 统计多随机种子的协方差与任务指标;本表为实验设计 |
γ=-1/(n-1) 定义了块负相关结构。n=1 时公式无定义,源码明确拒绝该配置。