我一直在使用OpenCV来调整大批量(100k+)的图像大小(16-24MP)。但是不知何故,使用CPU总是比使用GPU快30-50%。 由于我正在运行ryzen 1700x和1080ti,所以我本来期望情况会相反。 如果有人能给我一个提示,告诉我我做错了什么就太好了。 我正在运行OpenCV 4.0.0.pre和OpenCL 1.2
#!/usr/bin/python
import numpy as np
import cv2 as cv
import glob
from multiprocessing import Pool
import time
path =''
dic=[]
def resizer(file):
img = cv.imread(file)
height, width = img.shape[:2]
dim = float(width)/float(height)
if dim > 1:
width=4000
height= 4000/dim
start_time = time.time()
res = cv.resize(cv.UMat(img), (int(width), int(height)), interpolation=cv.INTER_CUBIC)
print("--- %s seconds ---" % (time.time() - start_time))
else:
width=4000*dim
height= 4000
start_time = time.time()
res = cv.resize(cv.UMat(img), (int(width), int(height)), interpolation=cv.INTER_CUBIC)
print("--- %s seconds ---" % (time.time() - start_time))
name=file.split('/')[-1]
cv.imwrite('/small/{}'.format(name), res)
for file in glob.glob(path+'*.JPG'):
dic.append(file)
if __name__ == "__main__":
pool=Pool(16)
pool.map(resizer, dic)
pool.terminate()
vips
或其Python绑定进行后处理或调整大小。 - undefinedcvtColor
中类似的行为。我试着比较了我从中获得灵感的现有实现和OpenCL变体,并没有发现OpenCL变体比并行化的基于CPU的实现更快。我需要进一步深入研究才能弄清楚发生了什么...目前还相当令人困惑,我对此也有同样的期望(而且我已经排除了与GPU内存之间的传输开销,据我所知)。 - undefined