Spaces:
Runtime error
Runtime error
Commit
·
28801c1
1
Parent(s):
dcc6440
description and title
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import kornia.color as color
|
|
| 9 |
|
| 10 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 11 |
model = Generator()
|
| 12 |
-
model_weights = torch.load('
|
| 13 |
model.load_state_dict(model_weights)
|
| 14 |
model = model.to(device)
|
| 15 |
model.eval()
|
|
@@ -52,6 +52,8 @@ def predict(image):
|
|
| 52 |
|
| 53 |
iface = gr.Interface(fn=predict,
|
| 54 |
inputs=gr.Image(type="pil"),
|
| 55 |
-
outputs=gr.Image(type="pil")
|
|
|
|
|
|
|
| 56 |
|
| 57 |
iface.launch()
|
|
|
|
| 9 |
|
| 10 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 11 |
model = Generator()
|
| 12 |
+
model_weights = torch.load('model.pth', map_location=device, weights_only=True)
|
| 13 |
model.load_state_dict(model_weights)
|
| 14 |
model = model.to(device)
|
| 15 |
model.eval()
|
|
|
|
| 52 |
|
| 53 |
iface = gr.Interface(fn=predict,
|
| 54 |
inputs=gr.Image(type="pil"),
|
| 55 |
+
outputs=gr.Image(type="pil"),
|
| 56 |
+
title="Colorize your grayscale images",
|
| 57 |
+
description="This model colorizes black and white images. Upload a black and white image and see the magic happen! (works best with 256x256)",)
|
| 58 |
|
| 59 |
iface.launch()
|
model.py
CHANGED
|
@@ -8,7 +8,6 @@ class DropoutAlways(nn.Dropout2d):
|
|
| 8 |
def forward(self, x):
|
| 9 |
return F.dropout2d(x, self.p, training=True)
|
| 10 |
|
| 11 |
-
|
| 12 |
class DownBlock(nn.Module):
|
| 13 |
def __init__(self, in_channels, out_channels, normalize=True):
|
| 14 |
super().__init__()
|
|
@@ -31,7 +30,7 @@ class UpBlock(nn.Module):
|
|
| 31 |
self.block = nn.Sequential(
|
| 32 |
nn.ConvTranspose2d(in_channels, out_channels, 4, 2, 1, bias=False if normalize else True),
|
| 33 |
nn.InstanceNorm2d(out_channels, affine=True) if normalize else nn.Identity(),
|
| 34 |
-
DropoutAlways(
|
| 35 |
nn.ReLU() if activation == 'relu' else nn.Tanh(),
|
| 36 |
)
|
| 37 |
|
|
|
|
| 8 |
def forward(self, x):
|
| 9 |
return F.dropout2d(x, self.p, training=True)
|
| 10 |
|
|
|
|
| 11 |
class DownBlock(nn.Module):
|
| 12 |
def __init__(self, in_channels, out_channels, normalize=True):
|
| 13 |
super().__init__()
|
|
|
|
| 30 |
self.block = nn.Sequential(
|
| 31 |
nn.ConvTranspose2d(in_channels, out_channels, 4, 2, 1, bias=False if normalize else True),
|
| 32 |
nn.InstanceNorm2d(out_channels, affine=True) if normalize else nn.Identity(),
|
| 33 |
+
DropoutAlways() if dropout else nn.Identity(),
|
| 34 |
nn.ReLU() if activation == 'relu' else nn.Tanh(),
|
| 35 |
)
|
| 36 |
|