圖像通道轉換[n c h w] 轉 [n h w c]

Tensorflow定義的tensor的shape爲[n,h,w,c],而我們直接讀取文件格式是[n,c,h,w],爲了轉成[n,h,w,c]形勢,可以採用三種方法:

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

img = img.reshape(img.shape[0], img.shape[2], img.shape[3], img.shape[1])

img_new = zeros((img.shape[0], img.shape[2], img.shape[3], img.shape[1]), dtype = np.float32)
for c in range(0, img.shape[1]):
    for i in range(0, img.shape[2]):
        for j in range(0, img.shape[3]):
            img_new[:,c,i,j] = img_new[:,i,j,c]

有問題歡迎指出來,咩~~~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章