Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -60,10 +60,16 @@ class ResNetGenerator(nn.Module):
|
|
| 60 |
def load_models():
|
| 61 |
device = torch.device("cpu")
|
| 62 |
checkpoint = torch.load("cyclegan_dogs2cats_final.pt", map_location=device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
gen_ab = ResNetGenerator(ngf=32, n_blocks=6)
|
| 64 |
gen_ba = ResNetGenerator(ngf=32, n_blocks=6)
|
| 65 |
-
gen_ab.load_state_dict(
|
| 66 |
-
gen_ba.load_state_dict(
|
| 67 |
gen_ab.eval()
|
| 68 |
gen_ba.eval()
|
| 69 |
return gen_ab, gen_ba
|
|
|
|
| 60 |
def load_models():
|
| 61 |
device = torch.device("cpu")
|
| 62 |
checkpoint = torch.load("cyclegan_dogs2cats_final.pt", map_location=device)
|
| 63 |
+
|
| 64 |
+
prefix_ab = "generators.a_to_b."
|
| 65 |
+
prefix_ba = "generators.b_to_a."
|
| 66 |
+
state_ab = {k[len(prefix_ab):]: v for k, v in checkpoint.items() if k.startswith(prefix_ab)}
|
| 67 |
+
state_ba = {k[len(prefix_ba):]: v for k, v in checkpoint.items() if k.startswith(prefix_ba)}
|
| 68 |
+
|
| 69 |
gen_ab = ResNetGenerator(ngf=32, n_blocks=6)
|
| 70 |
gen_ba = ResNetGenerator(ngf=32, n_blocks=6)
|
| 71 |
+
gen_ab.load_state_dict(state_ab)
|
| 72 |
+
gen_ba.load_state_dict(state_ba)
|
| 73 |
gen_ab.eval()
|
| 74 |
gen_ba.eval()
|
| 75 |
return gen_ab, gen_ba
|