justinpinkney / toonify

606 stars 73 forks source link

Assertion issue with StyleGAN-ADA #3

Closed smithee77 closed 3 years ago

smithee77 commented 3 years ago

Hi Justin, first of all thanks for your great toonify code 👍 I'm having an issue trying to use toonify with custom blended model - styleGAN2-ADA

I've generated a blended model using your colab notebook for "Network blending in StyleGAN-ADA". When I using this .pkl in toonify, I get an Assertion error. If I use a "normal" styleGAN2 .pkl (not ADA), it works fine.

The error is this:

/content/stylegan2/dnnlib/tflib/network.py in setstate(self, state) 276 277 # Set basic fields. --> 278 assert state["version"] in [2, 3, 4] 279 self.name = state["name"] 280 self.static_kwargs = util.EasyDict(state["static_kwargs"])

AssertionError:

many thanks in advance

Norod commented 3 years ago

The code in the original blending repo is compatible with StyleGAN2 not StyleGAN2 ADA. You can checkout SG2-ADA from any other repo and copy the relevant files to enable blending. E.G: https://github.com/Norod/my-colab-experiments/blob/master/Buntworthy_StyleGAN_ADA_blending_example.ipynb

@smithee77

smithee77 commented 3 years ago

Hi @Norod . That notebook is the one I used to generate my custom .pkl.

In toonify script, my issue is with line: , , Gs_blended = pretrained_networks.load_networks(blended_url) so, I suppose that problem is with pretrained_network.py file.

I've been looking for a similar file in the "Buntworthy_StyleGAN_ADA_blending_example.ipynb" notebook for stylegan2-ada, but there is only a "pretrained_network.py" file under /content/stylegan2 folder (which seems to be the same file than in toonify), but not under /content/stylegan2-ada folder.

Any clue? Maybe I misunderstood your solution. Thanks again

Norod commented 3 years ago

This is not specific to Toonify nor the Network-Swapper. You can try the following code, but please, it's not nice to use someone's repo as a general-purpose support channel.


%cd /content/stylegan2-ada

# Download the model of choice
import argparse
import numpy as np
import PIL.Image
import dnnlib
import dnnlib.tflib as tflib
import re
import sys
from io import BytesIO
import IPython.display
import numpy as np
from math import ceil
from PIL import Image, ImageDraw
import imageio
import os
import pickle
from dnnlib.tflib.autosummary import autosummary

tflib.init_tf()

# Choose a  pretrained model

network_pkl = 'https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada/pretrained/metfaces.pkl'

print('Loading networks from "%s"...' % network_pkl)
with dnnlib.util.open_url(network_pkl) as f:
    _G, _D, Gs = pickle.load(f)

noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]
smithee77 commented 3 years ago

Hi @Norod really sorry, newbie in python. Close issue, thanks for all