Einops.rearrange 的理解
einops 有很多人已经使用过了,它在深度学习,尤其是在 computer vision 中对 tensor 的操作上,显得非常方便。
由于已经有相当多的文档来讲它的基础,所以一般性的内容我就不再提了。本文只讲 einops.rearrange 里面一个我之前一直没弄明白的操作,来源于文档:https://einops.rocks/1-einops-basics/
rearrange(ims, 'b h w c -> h (b w) c')
v.s.
rearrange(ims, 'b h w c -> h (w b) c')
这两个操作的目的,都是为了对一个 batch 的图片进行一个转换。原始的 tensor 形状为4维,即 ( b , h , w , c ) (b, h, w, c) (b,h,