Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GAN模型PNNX转化问题 #3434

Closed
zhu-zhaofei opened this issue Dec 19, 2021 · 2 comments
Closed

GAN模型PNNX转化问题 #3434

zhu-zhaofei opened this issue Dec 19, 2021 · 2 comments

Comments

@zhu-zhaofei
Copy link

zhu-zhaofei commented Dec 19, 2021

error log | 日志或报错信息 | ログ

描述:pnnx转换,模型不能生成ncnn.parm和 ncnn.bin文件
日志:
pnnxparam = E://opt//ncnn//tools//pnnx//build_debug//install//bin//GFPGANCleanv1-NoCE-C2.pnnx.param
pnnxbin = E://opt//ncnn//tools//pnnx//build_debug//install//bin//GFPGANCleanv1-NoCE-C2.pnnx.bin
pnnxpy = E://opt//ncnn//tools//pnnx//build_debug//install//bin//GFPGANCleanv1-NoCE-C2.pnnx.py
optlevel = 2
device = cpu
inputshape = [1,3,512,512]f32
inputshape2 =
customop =
moduleop =
############# pass_level0
inline module = gfpgan.archs.gfpganv1_clean_arch.ResBlock
inline module = gfpgan.archs.gfpganv1_clean_arch.StyleGAN2GeneratorCSFT
inline module = gfpgan.archs.stylegan2_clean_arch.ConstantInput
inline module = gfpgan.archs.stylegan2_clean_arch.ModulatedConv2d
inline module = gfpgan.archs.stylegan2_clean_arch.StyleConv
inline module = gfpgan.archs.stylegan2_clean_arch.ToRGB
############# pass_level1
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
unknown Parameter value kind prim::Constant
no attribute value
no attribute value
no attribute value
no attribute value
############# pass_level2
############# pass_level3
############# pass_level4
############# pass_level5
############# pass_ncnn

model | 模型 | モデル

  1. original model

how to reproduce | 复现步骤 | 再現方法

1.下载GFPGANCleanv1-NoCE-C2,网址 https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth
2.pythor下保存track文件,示例代码如下

import cv2
import os
import torch
from basicsr.utils import img2tensor, tensor2img
from basicsr.utils.download_util import load_file_from_url
from facexlib.utils.face_restoration_helper import FaceRestoreHelper
from torchvision.transforms.functional import normalize

from gfpgan.archs.gfpganv1_arch import GFPGANv1
from gfpgan.archs.gfpganv1_clean_arch import GFPGANv1Clean

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def main():
    device = torch.device('cuda' if not torch.cuda.is_available() else 'cpu')
    gfpgan = GFPGANv1Clean(
        out_size=512,
        num_style_feat=512,
        channel_multiplier=2,
        decoder_load_path=None,
        fix_decoder=False,
        num_mlp=8,
        input_is_latent=True,
        different_w=True,
        narrow=1,
        sft_half=True)

    cropped_face = cv2.imread("E://workspace//GFPGAN-master//results//cropped_faces//00_01.png")
    cropped_face_t = img2tensor(cropped_face / 255., bgr2rgb=True, float32=True)
    normalize(cropped_face_t, (0.5, 0.5, 0.5), (0.5, 0.5, 0.5), inplace=True)
    cropped_face_t = cropped_face_t.unsqueeze(0).to(device)

    model_path = "..//experiments//pretrained_models//GFPGANCleanv1-NoCE-C2.pth"
    loadnet = torch.load(model_path)
    gfpgan.load_state_dict(loadnet['params_ema'], strict=True)
    gfpgan.eval()
    gfpgan = gfpgan.to(device)

    output = gfpgan(cropped_face_t, return_rgb=False)[0]
    restored_face = tensor2img(output.squeeze(0), rgb2bgr=True, min_max=(-1, 1))

    cv2.imshow("cropped_face_t", cropped_face)
    cv2.imshow("restored_face", restored_face)

    cv2.waitKey(2000)

    print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

    jit_track = torch.jit.trace(gfpgan, cropped_face_t)
    torch.jit.save(jit_track, "GFPGANCleanv1-NoCE-C2.trace")

    pass


if __name__ == "__main__":
    main()

3.pnnx.exe GFPGANCleanv1-NoCE-C2.trace inputshape=[1,3,512,512]

其他:
环境Window10 VS2017 x64 libtorch=1.10。

补充信息:
使用libtorch c++加载GFPGANCleanv1-NoCE-C2.trace可正常运行。
其他可能有用的信息如此连接描述 #3262 (comment)

@nihui

@nihui
Copy link
Member

nihui commented Dec 23, 2021

fixed in e0124db

感谢反馈

@zhu-zhaofei
Copy link
Author

感谢大佬FIXED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants