XingangPan / DragGAN

Official Code for DragGAN (SIGGRAPH 2023)
https://vcai.mpi-inf.mpg.de/projects/DragGAN/
Other
35.65k stars 3.45k forks source link

Is it possible to run DragGan from CPU? #143

Open testdami555 opened 1 year ago

testdami555 commented 1 year ago

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

Thanks!

kriswangchunyan commented 1 year ago

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

PDillis commented 1 year ago

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.