视频生成:运动藏在帧与帧之间
Video generation
拟合有限移动像素序列,检验正确单帧边缘遗漏了什么。
video-generation一帧好看,并不说明下一帧的点该去哪里
想象四帧画面,每帧只有一个亮点。单独看都合理,连起来却可能匀速移动、突然反向,或到处跳跃。图像模型即使学对了每一帧的分布,也可能没学到把这些帧连成视频的关系。
视频生成建模序列的分布,也可以以文字、起始帧或其他信号为条件。Ho等人的方法给图像扩散增加空间与时间处理;所选架构使用空间卷积,以及分别处理空间和时间的注意力。这是一种方法,不是视频生成的定义。建议先读自回归模型与视频理解。
分解序列,再问有限记忆丢了什么
X₁,…,XT表示各帧,c是给定条件。概率链式法则精确成立:
这不要求模型一定逐帧自回归采样。扩散模型可以联合去噪整个片段。下面用明确的有限概率,把时间依赖单独拿出来看。
一个点位于五格圆环,片段有四个位置。均匀选起点,再等概率选顺时针或逆时针方向,整个片段保持方向不变。5⁴个可能位置序列中只有十个合法片段。每一帧都均匀分布在五格上,因此独立近似为:
按计数拟合的一阶链学到:向两个相邻格移动的概率相同。它忘记了更早选定的方向:
这个模型生成的每一步都合法,却可能中途反向。在这个圆环上,连续两个位置可以确定方向;二阶链能够保留它:
对观测到的位置对,拟合后的下一位置是确定的。未观测上下文采用明确声明的均匀回退;从拟合起始位置对出发,不会到达这些上下文。设V为十个合法片段的集合,计数得到:
三个模型的单帧边缘仍完全相同。但在真实十片段分布上的平均负对数似然不同:
单位是每个四帧片段的自然对数,不是每像素或每秒。二阶模型的结论来自这个特意构造的匀向小过程,不证明两帧足以确定现实运动。
拟合计数,枚举所有片段
保存为video_generation.py,使用Python3.12与NumPy1.26.4。十个构造片段就是训练集。程序拟合边缘、一阶与二阶条件表,计算全部625个序列,并固定种子采样。它学习计数,不学习神经权重,也没有训练扩散网络。
若有S个位置、T帧和M个训练片段,拟合计数需要O(MT),一阶/二阶表分别需要O(S²)/O(S³)存储。这里精确枚举需要O(S^T T),只适合核查微小状态空间,不是可扩展的视频采样器;分类采样也明确使用枚举后的分布。
"""Original finite video model: one moving pixel on a five-cell ring."""
import itertools
import json
import numpy as np
def clips(direction=None):
if direction is not None and (type(direction) is not int or direction not in (-1, 1)):
raise ValueError('Direction must be None, -1 or 1')
return np.array([[(s + d*t) % 5 for t in range(4)]
for s in range(5) for d in ((-1, 1) if direction is None else (direction,))])
def sequences():
return np.array(list(itertools.product(range(5), repeat=4)))
def validate(x):
x = np.asarray(x)
if x.ndim != 2 or x.shape[1] != 4 or not 1 <= len(x) <= 10000:
raise ValueError('Expected 1..10000 clips with four positions')
if x.dtype.kind not in 'iu' or np.any((x < 0) | (x >= 5)):
raise ValueError('Positions must be integers 0..4')
return x
def normalize_rows(a):
totals = a.sum(axis=-1, keepdims=True)
return np.divide(a, totals, out=np.full_like(a, 1/a.shape[-1]), where=totals > 0)
def fit(x):
x = validate(x)
marginal = np.stack([np.bincount(x[:, t], minlength=5)/len(x) for t in range(4)])
one = np.zeros((5, 5)); two = np.zeros((5, 5, 5)); initial = np.zeros((5, 5))
np.add.at(initial, (x[:, 0], x[:, 1]), 1)
for t in range(1, 4): np.add.at(one, (x[:, t-1], x[:, t]), 1)
for t in range(2, 4): np.add.at(two, (x[:, t-2], x[:, t-1], x[:, t]), 1)
return marginal, normalize_rows(one), normalize_rows(two), initial/len(x)
def distribution(x, model, learned):
x = validate(x); marginal, one, two, initial = learned
if model == 'independent': return np.prod(marginal[np.arange(4), x], axis=1)
if model == 'first':
return marginal[0, x[:, 0]] * np.prod(one[x[:, :-1], x[:, 1:]], axis=1)
if model == 'second':
return initial[x[:, 0], x[:, 1]] * np.prod(two[x[:, :-2], x[:, 1:-1], x[:, 2:]], axis=1)
raise ValueError('Unknown model')
def coherent(x):
delta = np.diff(validate(x), axis=1) % 5
return np.all(delta == 1, axis=1) | np.all(delta == 4, axis=1)
def sample(model='second', count=1000, seed=23):
if type(count) is not int or not 1 <= count <= 10000: raise ValueError('Invalid count')
x = sequences(); p = distribution(x, model, fit(clips()))
return x[np.random.default_rng(seed).choice(len(x), size=count, p=p)]
def demo():
x = sequences(); learned = fit(clips()); valid = coherent(x); models = {}
for name in ['independent', 'first', 'second']:
q = distribution(x, name, learned)
marginals = [[float(q[x[:, t] == j].sum()) for j in range(5)] for t in range(4)]
models[name] = dict(total=float(q.sum()), coherent_mass=float(q[valid].sum()),
nll=float(-np.log(distribution(clips(), name, learned)).mean()),
marginals=marginals, sample_coherence=float(coherent(sample(name)).mean()))
model = distribution(x, 'second', learned)
reversed_q = distribution(x[:, ::-1], 'second', learned)
return dict(clips=clips().tolist(), models=models,
reverse_tv=float(abs(model-reversed_q).sum()/2),
given_start_mean=np.eye(5)[clips()[0:2]].mean(axis=0).tolist(),
scope='Finite count-fitted position chains; no video diffusion network or FVD computation.')
if __name__ == '__main__': print(json.dumps(demo(), indent=2))
连贯质量分别为.016、.25和1,NLL约为6.43775、3.68888、2.30259。固定种子的1,000次采样得到连贯比例.017、.258和1。采样误差和精确枚举是两件事。把给定起点的两种可能未来平均,后续帧会出现两个半亮点,而不是抽到一个具体未来。
用面向序列的协议评测序列
Fréchet Video Distance比较学习得到的视频特征空间中的矩,论文研究了I3D表示。固定参考实现对画面缩放、提取I3D激活,再调用分布距离函数。本例没有运行这些网络;连贯路径质量是为这个人工任务定义的指标,不是FVD。
比较系统前,应固定分辨率、帧率、时长、条件、样本数和特征提取器。短片段合理,不代表长程一致。所选视频扩散方法把延长和插帧作为条件生成问题;仅有架构不能保证正确延长。
本例顺/逆时针平衡,把所有片段倒放后分布不变。即使完美的分布比较,也应该判断相同。若目标只允许顺时针运动,倒放才会产生不相交的支持集。某个时间变化是不是错误,取决于任务分布,不只取决于变化的名称。
先预测序列,再运行程序
- 计算。 独立模型的连贯质量为什么是10/625? 答案:五个起点和两个固定方向给出十个片段;全部625个序列各有1/625的概率。
- 诊断。 一阶模型为什么会生成
[0,1,0,1]? 答案:每一步都走到相邻格,这正是它检查的全部信息。它忘记了初始方向;二阶模型给该序列零概率。 - 解释。 单帧质量相同,视频似然也相同吗? 答案:不同。各模型的单帧边缘都均匀,却给运动分配不同的联合概率,所以片段NLL不同。
- 迁移。 倒放总能被识别为分布错误吗? 答案:不能。它保留本例平衡方向分布;对于只许顺时针的目标,它会彻底改变分布。
区分架构、采样与评测
两篇选定论文处理不同问题:视频扩散提供架构和条件采样设置,FVD提出序列特征评测。小计数模型是对依赖关系的原创讲解,不是论文复现。继续读生成模型评测,了解矩比较的盲点。
先判断,再看解释
单帧边缘均匀,就保证运动连贯吗?
学习目标
- 沿时间分解视频分布。
- 计算不同记忆长度下的连贯路径。
- 区分单帧与视频评测。
先修与延伸
查看知识关联图 →参考文献
- Video Diffusion Models (v1)
Jonathan Ho; Tim Salimans; Alexey Gritsenko; William Chan; Mohammad Norouzi; David J. Fleet · 2022 - Towards Accurate Generative Models of Video: A New Metric & Challenges (v1)
Thomas Unterthiner; Sjoerd van Steenkiste; Karol Kurach; Raphael Marinier; Marcin Michalski; Sylvain Gelly · 2018 - google-research/google-research: frechet_video_distance/frechet_video_distance.py @932d468
google-research/google-research contributors
版本1 · 编写状态: 已完成记录中的技术复核
查看技术检查记录(AI)
Codex · 2026-09-20 · Single AI author checked Video Diffusion v1 section3/opening3.1, FVD v1 section2/I3D discussion and fixed FVD preprocessing code. Six paired equations and four explained exercises; original five-cell four-frame count fits, exhaustive625 sequences, coherence masses, clip NLL and reversal scope. No video diffusion training or FVD network execution.
- 核625序列穷举、.016/.25/1连贯质量、自然对数每片段NLL和方向倒放;单帧相同不代表联合相同,非FVD计算。
- 每题四张计算SVG;15数值/几何与36响应式组合通过,实看12张最终中文手机/英文桌面图。初版文案整理和英文手机标题越界修正保留;完整页面验收另记。
核对的来源位置:
- Video Diffusion Models (v1) · Read section3 and opening3.1; PDF3 viewed. Factorized architecture and extension setup only, not full reconstruction-guidance algorithm or benchmark reproduction.
- Towards Accurate Generative Models of Video: A New Metric & Challenges (v1) · Read section2 and I3D representation paragraphs; PDF2 viewed. No metric-network execution or human-study replication.
- google-research/google-research: frechet_video_distance/frechet_video_distance.py @932d468 · Read34-55,65-88,125-146: scaling, I3D and activation-distance call. Apache2 heading/opening only; no upstream execution.
相关主题