python uses 100% of single CPU (Google Compute Engine) - RealESRGAN

98 views Asked by At

I have the following setup:

  • Google Compute Engine VM with Nvidia Tesla T4 , 4CPU 16GB RAM
  • Conda environment where I am running the inference_realesrgan.py cloned from https://github.com/xinntao/Real-ESRGAN
  • Everything works as expected - the upscaling process is fine, but slow, the bottleneck is probably not the NVidia GPU, but the python process which uses only a single thread - probably for reading/converting/handling images by opencv? (see the attached image)
  • My goal: utilize all 4 CPUs during the upscale process
  • my initial command: conda activate base && python ~/Real-ESRGAN/inference_realesrgan.py -i ~/in -o ~/out -dn 1 -t 660 -g 0 --model_path ~/my_model.pth

The screenshot from Google Cloud VM - htop: enter image description here

Any hint/help appreciated!

1

There are 1 answers

1
hellork On

Python's Global Interpreter Lock (GIL) runs CPU tasks in a single thread. But the multiprocessing module might help, if there are enough images to warrant parallelizing.

from multiprocessing import Pool

def upscale_image(image_path):
    # Your upscaling code here
    # ...

if __name__ == '__main__':
    image_paths = [...]  # List of input images
    with Pool(processes=4) as pool:
        pool.map(upscale_image, image_paths)