How to fp16 image to fp32 image; Python numpy.transpose 详解
import numpy as np
import glob
import cv2
import scipy.misc
image_dir='./'
img_height = 64 # Height of the model input images
img_width = 64 # Width of the model input images
for pics in glob.glob(image_dir + '/*.fp16'):
picName = pics.split('/')[1]
image = np.fromfile(pics, dtype=np.float16)
image = np.reshape(image,[3,img_height, img_width]).astype(np.float32)
image = image * 255.0
image=np.transpose(image, (1,2,0))
#cv2.imwrite("cv_test.png", image)
cv2.imwrite( picName.split('.')[0] + ".png", image)
or
img_height = 64 # Height of the model input images
img_width = 64 # Width of the model input images
image_file = "5938dde6f51cd200a32e7608.fp16"
import numpy as np
image = np.fromfile(image_file, dtype=np.float16)
image = np.reshape(image, [3,img_height,img_width]).astype(np.float32)
image=image*255.0
image=np.transpose(image, (1,2,0))
import cv2
cv2.imwrite('t.jpg', image)
将Numpy数组保存为图像
https://vimsky.com/article/3697.html (good link)
Python numpy.transpose 详解
From: https://blog.csdn.net/u012762410/article/details/78912667
浙公网安备 33010602011771号