Spaces:
Sleeping
Sleeping
Update model.py
Browse files
model.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
netG
|
|
|
|
|
|
|
|
|
|
| 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
|