rosinality / stylegan2-pytorch

Implementation of Analyzing and Improving the Image Quality of StyleGAN (StyleGAN 2) in PyTorch
MIT License
2.73k stars 621 forks source link

About the Index error in fused_act.py #323

Open itigo-732 opened 2 years ago

itigo-732 commented 2 years ago

Usage environment: Windows11 python 3.7 CUDA 11.7

Issue Details: In the first program below, importing the pSp will result in "sources=[ os.path.join(module_path, 'fused_bias_act.cpp'), os.path.join(module_path, 'fused_bias_act_kernel.cu'), ]" Index Error occurs at "os.path.join(module_path, 'fused_bias_act_kernel.cu')" in

What should I do? The second one is the error that appears in that case.

`from models.psp import pSp
from utils.alignment import align_face
from argparse import Namespace
import sys
import torch
from torchvision import transforms
import dlib
import numpy as np

def latent_variables(path, name:str):
    model_path = 'e4e_ffhq_encode.pt'
    ckpt = torch.load(model_path)

    opts = ckpt['opts']
    opts['checkpoint_path'] = model_path

    opts= Namespace(**opts)
    net = pSp(opts)
    net.eval().to('cuda')
    input_image = run_alignment(path)

    transform_fn = transforms.Compose([
        transforms.Resize((256, 256)),
        transforms.ToTensor(),
        transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])])

    transformed_image = transform_fn(input_image)

    with torch.no_grad():
        images, latents = net(transformed_image.unsqueeze(0).to('cuda').float(), randomize_noise=False, return_latents=True)

    latent_array = latents.to('cpu').numpy()
    savename = "../" + name + ".npy"
    np.save(savename, latent_array)

def run_alignment(image_path):
    predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
    aligned_image = align_face(filepath=image_path, predictor=predictor)
    print("Aligned image has shape: {}".format(aligned_image.size))
    return aligned_image

if __name__ == "__main__":
    path = sys.argv[1]
    name = sys.argv[2]
    latent_variables(path, name)`
`例外が発生しました: IndexError
list index out of range
  File "C:\Users\shini\Desktop\flask2\encoder4editing\models\stylegan2\op\fused_act.py", line 13, in <module>
    os.path.join(module_path, 'fused_bias_act_kernel.cu'),
  File "C:\Users\shini\Desktop\flask2\encoder4editing\models\stylegan2\op\__init__.py", line 1, in <module>
    from .fused_act import FusedLeakyReLU, fused_leaky_relu
  File "C:\Users\shini\Desktop\flask2\encoder4editing\models\stylegan2\model.py", line 7, in <module>
    from models.stylegan2.op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d
  File "C:\Users\shini\Desktop\flask2\encoder4editing\models\encoders\psp_encoders.py", line 9, in <module>
    from models.stylegan2.model import EqualLinear
  File "C:\Users\shini\Desktop\flask2\encoder4editing\models\psp.py", line 6, in <module>
    from models.encoders import psp_encoders
  File "C:\Users\shini\Desktop\flask2\encoder4editing\latent.py", line 1, in <module>
    from models.psp import pSp`
JSHZT commented 1 year ago

I also encountered the same problem, did you solve it?