Armyman91 commited on
Commit
1ea937d
·
verified ·
1 Parent(s): 29235df

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +17 -14
model.py CHANGED
@@ -1,15 +1,18 @@
1
- # model.py
2
- import torch
3
- from models.networks import define_G
4
-
5
- def load_generator(model_path):
6
- # Define the generator with default CycleGAN config
7
- netG = define_G(
8
- input_nc=1, output_nc=1, ngf=64,
9
- netG='resnet_9blocks', norm='instance',
10
- use_dropout=False, init_type='normal', init_gain=0.02, gpu_ids=[]
11
- )
12
- state_dict = torch.load(model_path, map_location='cpu')
13
- netG.load_state_dict(state_dict)
14
- netG.eval()
 
 
 
15
  return netG
 
1
+ import torch
2
+ from models.networks import define_G
3
+
4
+ def load_generator(checkpoint_path):
5
+ checkpoint = torch.load(checkpoint_path, map_location='cpu')
6
+ if 'G_A' in checkpoint:
7
+ state_dict = checkpoint['G_A']
8
+ elif 'state_dict' in checkpoint:
9
+ state_dict = checkpoint['state_dict']
10
+ else:
11
+ state_dict = checkpoint
12
+
13
+ # Match your trained generator architecture here!
14
+ 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=[])
15
+
16
+ netG.load_state_dict(state_dict)
17
+ netG.eval()
18
  return netG