总结:torch版cuda最快,cpu次之,python最慢。
import time import torch import numpy as np import cv2 if __name__ == '__main__': path=r'D:\111.jpg' img_ = cv2.imread(path) start = time.time() for j in range(500): #python中如果是除法,img=img/255.0 会很快;img1=img/255.0 就会比较慢,一张图片需要156ms img=img_/255.0 image = np.transpose(img, (2, 0, 1)) img2 = torch.from_numpy(image).float()#.unsqueeze(0) # time.sleep(0.007) print('time1',time.time()-start) img = cv2.imread(path) start = time.time() for j in range(500): # img_=img_/255.0 img2 = torch.from_numpy(img) img2=img2.cuda().float().div(255.0)#.un