File size: 848 Bytes
03ee8ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import dnnlib
import numpy as np
import PIL.Image
import torch

import legacy
import pickle

import torchvision.transforms as transforms
from PIL import Image

network_pkl = '/home/rahul/Downloads/network-snapshot-003200.pkl'

with open(network_pkl, 'rb') as f:
    G = pickle.load(f)['G_ema'].cpu()  # torch.nn.Module
z = torch.randn([1, G.z_dim]).cpu()  # latent codes
c = None  # class labels (not used in this example)
img = G(z, c)
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
#um = torch..nn.Upsample(scale_factor=2, mode='bilinear')
#img=um(img)
image=PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB')
transform = transforms.Resize((image.height * 2, image.width * 2), interpolation=transforms.InterpolationMode.BILINEAR)
upscaled_image = transform(image)
upscaled_image.save('/home/rahul/Downloads/seed1.png')