FontStyleTransfer / model.py
Armyman91's picture
Update model.py
1ea937d verified
Raw History Blame Contribute Delete
620 Bytes
import torch
from models.networks import define_G
def load_generator(checkpoint_path):
checkpoint = torch.load(checkpoint_path, map_location='cpu')
if 'G_A' in checkpoint:
state_dict = checkpoint['G_A']
elif 'state_dict' in checkpoint:
state_dict = checkpoint['state_dict']
else:
state_dict = checkpoint
# Match your trained generator architecture here!
netG = define_G(input_nc=1, output_nc=1, ngf=64, netG='unet_128', norm='batch', use_dropout=False, init_type='normal', init_gain=0.02, gpu_ids=[])
netG.load_state_dict(state_dict)
netG.eval()
return netG