【代码学习】einops,更简单的张量变化

官方教程:https://github.com/arogozhnikov/einops/blob/master/docs/2-einops-for-deep-learning.ipynb

常见操作:

  1. 维度变换 rearrange
维度变换
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)

你可能感兴趣的:(【杂学】,学习)