What is the correct way to change image channel ordering between channels first and channels last?

后端 未结 5 700
暗喜
暗喜 2021-02-02 07:28

I can not for the life of me figure out how to switch the image ordering. images are read in (x,x,3) format, theano requires it to be in (3,x,x) format. I tried changing the ord

5条回答
  •  感动是毒
    2021-02-02 08:04

    Using np.moveaxis is effective, but I have found that np.einsum is much faster.

    x = np.zeros((12,12,3))
    %timeit np.moveaxis(x,-1,0)
    #yields 7.46 µs ± 312 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
    
    %timeit np.einsum('ijk->kij',x)
    #yields 1.11 µs ± 31 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    

提交回复
热议问题