官方教程:https://github.com/arogozhnikov/einops/blob/master/docs/2-einops-for-deep-learning.ipynb
常见操作:
维度变换
y = rearrange(x, 'b c h w -> b h w c') # 已经 表明 x的每个轴 变量 `b c h w`
guess(y.shape)
flatten
y = rearrange(x, 'b c h w -> b (c h w)')
guess(y.shape)
space-to-depth
y = rearrange(x, 'b c (h h1) (w w1) -> b (h1 w1 c) h w', h1=2, w1=2)
guess(y.shape)
depth-to-space
y = rearrange(x, 'b (h1 w1 c) h w -> b c (h h1) (w w1)', h1=2, w1=2)
guess(y.shape)