HighCWu / waifu2x-tfjs

Image super-resolution using Tensorflow.js .
MIT License
51 stars 18 forks source link

GPU Memory is falsely potrait #2

Closed PraveenAsh closed 5 years ago

PraveenAsh commented 5 years ago

The tf.backend support webgl will use the GPU on the browser. But, the GPU memory available slider feels like a misnomer or falsely being used.

If what I have traced is right, then the this.state.memory is never in used in the class Waifu2x. Even if it were used, the tensorflow.backend api doesn't permit to set a specific GPU memory size for the usage. I just need to know why memory variable is being used. Is it for the future or is it actually capable of accessing the GPU memory?

HighCWu commented 5 years ago

@PraveenAsh In fact, the value of this slider is the value of your own computer's memory. Exceeding a moderate value will cause Tensor to stay in the operation for too long, resulting in webgl errors. I have not optimized the operation, so in this implementation I may not release the Tensor in time or perform the operation step by step, so I slice the image according to the size of the input memory, but this will result in a slice of the trace at the intersection of each slice. Too large value of the slider may cause this error and make the GPU crash:

WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost

I don't have time to find a way to optimize this problem.

PraveenAsh commented 5 years ago

Okay seems fair. I'm assuming it exists solely because CPU memory could affect the GPU's optimization.

Apart from this, can GPU withstand VGG19? Does it lead to the same error perhaps even earlier while inference?

HighCWu commented 5 years ago

@PraveenAsh In fact, this is more dependent on the size of the input if the code is not optimized. In waifu2x, some input images are larger than 256x256, which causes the output of the webgl operation to wait too long, resulting in an error. But small inputs are not easy to make such mistakes. However, the vgg19 model may be too large, and the tensorflow officially recommended tfjs model file size is less than 30M. So, compared to vgg19, I might recommend you to use mobilenet. There is a fast style transfer repo, which has a small model and supports large image input. reiinakano/arbitrary-image-stylization-tfjs