kritiksoman / GIMP-ML

AI for GNU Image Manipulation Program
https://github.com/kritiksoman/tmp/blob/master/GIMP-ML%20Presentation.pdf
MIT License
1.43k stars 133 forks source link

CUDA out of memory with super-resolution plugin #20

Open YAFU opened 4 years ago

YAFU commented 4 years ago

System: Kubuntu linux - GTX 960 4GB - Gimp 2.10.18

If I apply Super-resolution plugin to any image larger than about 600x600 px it quickly fills up the 4GB of vRAM and I get the following error:

An error occurred running python-fu-super-resolution
RuntimeError: CUDA out of memory. Tried to allocate 66.00 MiB (GPU 0; 3.95 GiB total capacity; 3.10 GiB already allocated; 53.38 MiB free; 3.12 GiB reserved in total by PyTorch)
Traceback (most recent call last):
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 740, in response
    dialog.res = run_script(params)
  File "/usr/lib/gimp/2.0/python/gimpfu.py", line 361, in run_script
    return apply(function, params)
  File "/home/yafu/GIMP-ML/gimp-plugins/super_resolution.py", line 100, in super_resolution
    cpy = getnewimg(imgmat,scale)
  File "/home/yafu/GIMP-ML/gimp-plugins/super_resolution.py", line 56, in getnewimg
    HR_4x = model(im_input)
  File "/home/yafu/GIMP-ML/gimp-plugins/gimpenv/lib/python2.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yafu/GIMP-ML/gimp-plugins/pytorch-SRResNet/srresnet.py", line 61, in forward
    out = self.residual(out)
  File "/home/yafu/GIMP-ML/gimp-plugins/gimpenv/lib/python2.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yafu/GIMP-ML/gimp-plugins/gimpenv/lib/python2.7/site-packages/torch/nn/modules/container.py", line 100, in forward
    input = module(input)
  File "/home/yafu/GIMP-ML/gimp-plugins/gimpenv/lib/python2.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yafu/GIMP-ML/gimp-plugins/pytorch-SRResNet/srresnet.py", line 18, in forward
    output = self.in2(self.conv2(output))
  File "/home/yafu/GIMP-ML/gimp-plugins/gimpenv/lib/python2.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yafu/GIMP-ML/gimp-plugins/gimpenv/lib/python2.7/site-packages/torch/nn/modules/instancenorm.py", line 49, in forward
    self.training or not self.track_running_stats, self.momentum, self.eps)
  File "/home/yafu/GIMP-ML/gimp-plugins/gimpenv/lib/python2.7/site-packages/torch/nn/functional.py", line 1685, in instance_norm
    use_input_stats, momentum, eps, torch.backends.cudnn.enabled
RuntimeError: CUDA out of memory. Tried to allocate 66.00 MiB (GPU 0; 3.95 GiB total capacity; 3.10 GiB already allocated; 33.44 MiB free; 3.12 GiB reserved in total by PyTorch)

As a request derived from this problem, as vRAM capacity can be very varied depending on the users, it would be great if the user could choose between CPU or GPU in the plugins that autodetect CUDA to work. Thanks!

datalot-369 commented 4 years ago

I have no measured the vRAM consumption but at least my 4GB system RAM is not enough for this plugin/filter with medium images (Between 1 and 2 MPx).

I will try with a little image to try to get a replicate.

Edit 1:

I run this plugin with the process selected on htop to kill it in the case it start taking my swap memory.

kritiksoman commented 4 years ago

try Force CPU

kritiksoman commented 4 years ago

check now (set "Use as filter" to True)

datalot-369 commented 4 years ago

Not the best I have seen, for sure:

original upscaled


Congratulations to the GIMP ML team!

kritiksoman commented 4 years ago

I tried for 1166X672 image on i5 processor, 4gb RAM, macOS. It took 5 minutes to produce 4664X2688 image. Will try to optimise it further.