【问题标题】:Change image channel ordering from channel first to last将图像通道顺序从通道第一个更改为最后一个
【发布时间】:2018-03-29 14:34:31
【问题描述】:

我想将此 numpy 图像数组的顺序更改为 channel_last training_data : (2387, 1, 350, 350) 到 (2387,350,350,1) 验证数据:(298、1、350、350)到(298、350、350、1) testing_data : (301, 1, 350, 350) 到 (301, 350, 350, 1)

我试过了,但是没用

np.rollaxis(training_data,0,3).shape
np.rollaxis(validation_data,0,3).shape
np.rollaxis(testing_data,0,3).shape

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    您需要像这样的np.transpose 方法:

    training_data = np.transpose(training_data, (0, 2,3,1)
    

    其他的也一样

    【讨论】:

      【解决方案2】:

      如果您移动的轴的长度为1,则可以进行简单的整形:

      a = np.arange(24).reshape(2, 1, 3, 4)
      
      # Three different methods:
      b1 = a.reshape(2, 3, 4, 1)
      b2 = np.moveaxis(a, 1, 3)
      b3 = a.transpose(0, 2, 3, 1)
      
      # All give the same result:
      np.all(b1 == b2) and np.all(b2 == b3)
      # True
      

      【讨论】:

        【解决方案3】:

        这样做:

        np.rollaxis(array_here,axis_to_roll,to_where)
        

        对于您的情况,您希望将轴 0 滚动到最后一个位置(超过 3),因此您必须将 to_where 设置为 4(超过 3)。

        这将工作(个人测试):

        np.rollaxis(train_data,0,4)
        

        【讨论】:

          猜你喜欢
          • 2018-10-30
          • 2017-10-05
          • 1970-01-01
          • 2018-08-20
          • 1970-01-01
          • 1970-01-01
          • 2016-06-28
          • 2022-01-04
          • 1970-01-01
          相关资源
          最近更新 更多