default="sample_strip_config.yaml") args = parser.parse_args() args.latent = 512 args.n_mlp = 8 yaml_config = {} with open(args.config, 'r') as stream: try: yaml_config = yaml.load(stream) except yaml.YAMLError as exc: print(exc) g_ema = Generator(args.size, args.latent, args.n_mlp, channel_multiplier=args.channel_multiplier).to(device) new_state_dict = g_ema.state_dict() checkpoint = torch.load(args.ckpt) ext_state_dict = torch.load(args.ckpt)['g_ema'] new_state_dict.update(ext_state_dict) g_ema.load_state_dict(new_state_dict) g_ema.eval() g_ema.to(device) if args.truncation < 1: with torch.no_grad(): mean_latent = g_ema.mean_latent(args.truncation_mean) else: mean_latent = None
transforms.Resize(resize), transforms.CenterCrop(resize), transforms.ToTensor(), transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]), ] ) imgs = [] for imgfile in args.files: img = transform(Image.open(imgfile).convert('RGB')) imgs.append(img) imgs = torch.stack(imgs, 0).to(device) g_ema = Generator(args.size, 512, 8) g_ema.load_state_dict(torch.load(args.ckpt)['g_ema'], strict=False) g_ema.eval() g_ema = g_ema.to(device) with torch.no_grad(): noise_sample = torch.randn(n_mean_latent, 512, device=device) latent_out = g_ema.style(noise_sample) latent_mean = latent_out.mean(0) latent_std = ((latent_out - latent_mean).pow(2).sum() / n_mean_latent) ** 0.5 percept = lpips.PerceptualLoss( model='net-lin', net='vgg', use_gpu=device.startswith('cuda') )