[英]Using multiprocessing to process image but no performance gain with 8 cpus
I got a function called cartoonize(image_path)
, which takes 'path/to/image' as an argument. 我得到了一个名为
cartoonize(image_path)
的函数,该函数将'path / to / image'作为参数。 The script is a bit hefty takes a couple of minutes to process a 1920x1080 sized image. 该脚本需要花费几分钟才能处理1920x1080尺寸的图像。 I tried to use all my
8 cores
using multiprocessing module
, but there is no performance gain I see with the following code. 我尝试通过
multiprocessing module
使用所有8 cores
,但是以下代码没有提高性能。 Another problem is how to save the image. 另一个问题是如何保存图像。 It returns a CV2 object.
它返回一个CV2对象。 Normally, I save the image to the disk by
see below code
, but with multiprocessing it is giving error "img is not a numpy array, neither a scalar."
通常,我通过
see below code
将图像保存到磁盘,但是通过多处理,它会给出错误"img is not a numpy array, neither a scalar."
I also want a performance gain, which I can't figure out how to do it efficiently. 我还希望获得性能提升,但我不知道如何有效地做到这一点。
out_final = cartoonize('path/to/image'))
cv2.imwrite('cartoon.png', out_final)
import multiprocessing
if __name__ == '__main__':
# mark the start time
startTime = time.time()
print "cartoonizing please wait ..."
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
pool_outputs = pool.apply_async(cartoonize, args=(image_path,))
pool.close()
pool.join()
print ('Pool:', pool_outputs)
# mark the end time
endTime = time.time()
print('Took %.3f seconds' % (startTime - endTime))
Question : multiprocessing it is giving error "img is not a numpy array, neither a scalar."
问题 :多重处理给出错误“ img不是一个numpy数组,也不是标量。”
pool_outputs = pool.apply_async(cartoonize, args=(image_path,))
Your code returns AsyncResult
您的代码返回
AsyncResult
Python » 3.6.1 Documentation » multiprocessing.pool.AsyncResult
Python»3.6.1文档 » multiprocessing.pool.AsyncResult
class multiprocessing.pool.AsyncResult The class of the result returned by Pool.apply_async() and Pool.map_async().class multiprocessing.pool.AsyncResult Pool.apply_async()和Pool.map_async() 返回的结果的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.