DragGAN icon indicating copy to clipboard operation
DragGAN copied to clipboard

Is it possible to run DragGan from CPU?

Open testdami555 opened this issue 1 year ago • 2 comments

Is it possible to run DragGan from CPU? What configuration would be required to get it to work? Operating system: Windows 10

Thanks!

testdami555 avatar Jun 30 '23 14:06 testdami555

没有配置GPU环境默认的就是CPU环境,但是CPU是很慢的,建议有条件还是使用GPU吧

kriswangchunyan avatar Jul 03 '23 02:07 kriswangchunyan

It is possible, but you need to load the Generator in the correct way, so you'll most likely have to tinker with the code. For example, to load the Generator to the CPU, you need to do the following:

# Load the Generator as usual
import legacy
import dnnlib

network_pkl = 'path/to/network.pkl'  # This can also be a URL

with dnnlib.util.open_url(network_pkl) as f:
    G = legacy.load_network_pkl(f)['G_ema'].eval().requires_grad_(False)

# Move to the CPU
import functools
G.forward = functools.partial(G.forward, force_fp32=True)

Then you're good to go. Might have a look to implement this later on, if I have the time. Otherwise, this is basically how you should do it.

PDillis avatar Jul 03 '23 09:07 PDillis