dsanno / chainer-neural-style

implementation of neural style using Chainer
Other
18 stars 6 forks source link

How to reduce the GPU memory using #3

Open dovanchan opened 7 years ago

dovanchan commented 7 years ago

Thanks for your contribution This implement is very beatiful .but I have a question that how to reduce the memory using? It's about 2.5G taking up now~ Do you have some suggestion . or Will you update a new algorithm for solve this problem~

dsanno commented 7 years ago

It is usual to consume 2.5G memory. VGG model takes a large amount of memory. Memory usage depends on image size and you can reduce memory usage by using -w image_size(or --width image_size) option with small size. I don't know another way to reduce memory.

dovanchan commented 7 years ago

I know a way to reduce memory.
Try to use Adam optimizer,It will reduce the memory three times,(less than 1g),but I just know this way,I dont know how to implement it in chainer,Hopefully one day you can update it and let the user can choose Adam optimizer;

dsanno commented 7 years ago

Thank you for your reply. Chainer supports Adam optimizer and it is easy to use it. To use Adam, replace this line(https://github.com/dsanno/chainer-neural-style/blob/master/src/style_transfer_runner.py#L52) with optimizer = chainer.optimizers.Adam(10.0) (I don't know the optimal learning rate for Adam optimizer, but this value seems to work.)

I've tried Adam, but memory usage is almost the same as LBFGS.

dovanchan commented 7 years ago

Hi,Now I have tried Adam,I found that it's useful for using Adam,It just spend a half memory. Two more question 1、Do you know how to limit the gpu usage(for example limit it in 1G) in this chainer neural style code. 2、What is the meaning of “--resolution (1,2,3)”

dsanno commented 7 years ago

1、Do you know how to limit the gpu usage(for example limit it in 1G) in this chainer neural style code.

I think Chainer doesn't have a function to limit GPU usage. Ask Chainer developers.

2、What is the meaning of “--resolution (1,2,3)”

"resolution" means style transfer starts from small image and double the size of it some iterations. For example --resolution 3 --width 512

  1. starts from 128px image and
  2. optimize image for some iterations and double the size of the image (to 256px)
  3. optimize image for some iterations and double the size of the image (to 512px)
  4. optimize image for some iterations and style transfer finishes.