eladrich / pixel2style2pixel

Official Implementation for "Encoding in Style: a StyleGAN Encoder for Image-to-Image Translation" (CVPR 2021) presenting the pixel2style2pixel (pSp) framework
https://eladrich.github.io/pixel2style2pixel/
MIT License
3.2k stars 568 forks source link

How to run inference on other gpu? #249

Closed olegkorshunov closed 2 years ago

olegkorshunov commented 2 years ago

I want to run inference on cuda:2, I rewrote the code like this

device='cuda:2'
opts = Namespace(**opts)
opts.device=device
net = pSp(opts)
net.eval()
net.to(opts.device)

and in inference.py I also replaced everything

.cuda() -> .to(device)
.to('cuda') -> .to(device)

but it isn't worked, I just get a brown image, on cuda:0 everything is okey

yuval-alaluf commented 2 years ago

I would leave the code as is and simply run the script with CUDA_VISIBLE_DEVICES=2

olegkorshunov commented 2 years ago

I would leave the code as is and simply run the script with CUDA_VISIBLE_DEVICES=2 I am not sure, mb I doing smhng wrong, I try it command

!CUDA_VISIBLE_DEVICES=2, python scripts/inference.py \
--exp_dir=./experiment \
--checkpoint_path=./pretrained_models/psp_ffhq_toonify.pt \
--data_path=./photo_crops \
--test_batch_size=2 \
--test_workers=2 \
--couple_outputs

and got this error

Loading pSp from checkpoint: ./pretrained_models/psp_ffhq_toonify.pt
Traceback (most recent call last):
File "scripts/inference.py", line 169, in <module>
run()
File "scripts/inference.py", line 56, in run
net = pSp(opts)
File "/home/uadmin/Projects/gan/pixel2style2pixel/./models/psp.py", line 34, in __init__
self.load_weights()
File "/home/uadmin/Projects/gan/pixel2style2pixel/./models/psp.py", line 57, in load_weights
self.__load_latent_avg(ckpt)
File "/home/uadmin/Projects/gan/pixel2style2pixel/./models/psp.py", line 131, in __load_latent_avg
self.latent_avg = ckpt["latent_avg"].to(self.opts.device)
RuntimeError: CUDA error: invalid device ordinal
olegkorshunov commented 2 years ago

I would leave the code as is and simply run the script with CUDA_VISIBLE_DEVICES=2

sorry my bad I forgot I also changed the PSP, everything is working now thx :-)