nagadomi / waifu2x

Image Super-Resolution for Anime-Style Art
http://waifu2x.udp.jp/
MIT License
27.33k stars 2.71k forks source link

LuaJIT: Not enough memory #376

Closed TheRealJayjayli closed 3 years ago

TheRealJayjayli commented 3 years ago

When creating the training data (160x~4K PNGs), I get an out of memory error:

/home/jaydn/torch/install/bin/luajit: not enough memory.................................]  ETA: 29s30ms | Step: 252ms 

In top, I do not see luajit using more than 4GB out of my available 32GB of RAM.

If I only use 5 images for training data, it works fine, however during training I get the following error:

jaydn@JaydnsPCLinux:~/waifu2x$ th train.lua -model_dir models/my_model -method scale -thread 8
0 small images are removed  
# make validation-set   
/home/jaydn/torch/install/bin/luajit: /home/jaydn/torch/install/share/lua/5.1/threads/threads.lua:183: [thread 4 callback] not enough memory
stack traceback:
    [C]: in function 'error'
    /home/jaydn/torch/install/share/lua/5.1/threads/threads.lua:183: in function 'dojob'
    /home/jaydn/torch/install/share/lua/5.1/threads/threads.lua:264: in function 'synchronize'
    train.lua:292: in function 'make_validation_set'
    train.lua:579: in function 'train'
    train.lua:718: in main chunk
    [C]: in function 'dofile'
    ...aydn/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
    [C]: at 0x00405d50

However, luajit only uses 2GB of RAM before crashing. I am running Ubuntu 16.04 x86_64.

nagadomi commented 3 years ago

4K image requires 4096*4096*3(channels)*4(sizeof(float)) = 196MB memory, x 160 images = 30GB. Considering the temporary buffer, it is just out of memory. If you want to use 4K images, I think it is better to divide them into pieces of about 512x512.