hzwer / ECCV2022-RIFE

ECCV2022 - Real-Time Intermediate Flow Estimation for Video Frame Interpolation
MIT License
4.51k stars 446 forks source link

Image encoding is a bottleneck - Implement multithreaded image writing? #95

Open n00mkrad opened 3 years ago

n00mkrad commented 3 years ago

Using uncompressed BMP instead of PNG increased my speed from ~14 FPS at 1080p to ~18 FPS, proving that the image encoding slows things down and bottlenecks the GPU.

Is it possible to run image writing in several threads to speed this up?

talosh commented 3 years ago

True, noticed it as well while doing sequence processing with 16bit fp open-exr. Currently I'm giving each frame a thread:

path = os.path.join(os.path.abspath(args.output), '{:0>7d}.exr'.format(cnt)) p = mp.Process(target=cv2.imwrite, args=(path, item[:, :, ::-1], [cv2.IMWRITE_EXR_TYPE, cv2.IMWRITE_EXR_TYPE_HALF], )) p.start()

and limiting process number roughly by adjusting output queue size:

write_buffer = Queue(maxsize=mp.cpu_count() - 3)

might be wrong way doing it but works for now. Full code: https://github.com/talosh/flameTimewarpML/blob/main/bundle/inference_sequence.py