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

The converted model generate blur images #18

Closed
TechSheng opened this issue Aug 11, 2021 · 5 comments
Closed

The converted model generate blur images #18

TechSheng opened this issue Aug 11, 2021 · 5 comments

Comments

@TechSheng
Copy link

TechSheng commented Aug 11, 2021

After the conversion, the model generates the blur images. I use the file "convert_rosinality_ckpt.py" to convert the "550000.pt"(the pretrained model on 256 provided by "https://github.com/rosinality/stylegan2-pytorch") model. In order to see the generated images by styleganv2 pretrained parameters, I modified the

img = self.student(style)["img"]
with "img = self.synthesis_net(style)["img"]" to generate some images. Here are some images below.
image image image image
I don't know what caused this. Have you ever encountered this problem? @bes-dev

@bes-dev
Copy link
Owner

bes-dev commented Aug 11, 2021

It works correct on my side. For exmaple 550000.pt:
Screenshot from 2021-08-11 20-33-39

@TechSheng
Copy link
Author

Thank you for your reply! I use the latest code in your MobileStyleGAN repository. However, I can't generate sharp images. Can you share your local "convert_rosinality_ckpt.py" file with me? or the converted ckpt file? I want to find the reason.

@bes-dev
Copy link
Owner

bes-dev commented Aug 13, 2021

@zuimeiyujianni I just do something like this:

  • clone latest version of MobileStyleGAN.pytorch
    git clone https://github.com/bes-dev/MobileStyleGAN.pytorch.git && cd MobileStyleGAN.pytorch
  • downnload 550000.pt
    gdown https://drive.google.com/uc?id=1PQutd-JboOCOZqmd95XWxWrO8gGEvRcO
  • convert 550000.pt to internal format:
    python convert_rosinality_ckpt.py --ckpt 550000.pt --ckpt-mnet mnet.ckpt --ckpt-snet snet.ckpt
  • create config.json:
{
    "logger": {
        "type": "NeptuneLogger",
        "params": {
            "offline_mode": true,
            "project_name": "bes-dev/stylegan2_compression",
            "experiment_name": "baseline"
        }
    },
    "trainset": {
        "emb_size": 512,
        "n_batches": 10000
    },
    "valset": {
        "emb_size": 512,
        "n_batches": 200
    },
    "teacher": {
        "mapping_network": {
            "name": "mnet.ckpt"
        },
        "synthesis_network": {
            "name": "snet.ckpt"
        }
    },
    "distillation_loss": {
        "perceptual_size": 256,
        "loss_weights": {
            "l1": 1.0,
            "l2": 1.0,
            "loss_p": 1.0,
            "loss_g": 0.5
        }
    },
    "trainer": {
        "monitor": "kid_val",
        "monitor_mode": "min",
        "style_mean": 4096,
        "style_mean_weight": 0.5,
        "num_workers": 0,
        "lr_student": 5e-4,
        "lr_gan": 5e-4,
        "batch_size": 2,
        "max_epochs": 100,
        "mode": "g,d",
        "reg_d_interval": 16,
        "truncated": false
    }
}
  • run compare.py demo:
python compare.py --cfg config.json --ckpt ""

So, you should see the correct images generated by StyleGAN2 on the left (and noise on the right, because your MobileStyleGAN model is not trained yet)

@bes-dev
Copy link
Owner

bes-dev commented Aug 13, 2021

@zuimeiyujianni so, we improve user experience a little bit. Just do like:

$ git clone https://github.com/bes-dev/MobileStyleGAN.pytorch.git && cd MobileStyleGAN.pytorch
$ gdown https://drive.google.com/uc?id=1PQutd-JboOCOZqmd95XWxWrO8gGEvRcO
$ python convert_rosinality_ckpt.py --ckpt 550000.pt --ckpt-mnet mnet.ckpt --ckpt-snet snet.ckpt --cfg-path config.json
$ python demo.py --cfg config.json --ckpt "" --generator teacher

It works well for me.

@TechSheng
Copy link
Author

Thank you for your reply!!!. I have overcome this problem.

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