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]
有問題歡迎指出來,咩~~~