2017-11-30 05:45:19 +00:00
|
|
|
# full assembly of the sub-parts to form the complete net
|
|
|
|
|
2018-11-10 22:42:16 +00:00
|
|
|
import torch.nn.functional as F
|
|
|
|
|
2017-11-30 05:45:19 +00:00
|
|
|
from .unet_parts import *
|
2017-08-16 12:24:29 +00:00
|
|
|
|
|
|
|
class UNet(nn.Module):
|
|
|
|
def __init__(self, n_channels, n_classes):
|
|
|
|
super(UNet, self).__init__()
|
|
|
|
self.inc = inconv(n_channels, 64)
|
|
|
|
self.down1 = down(64, 128)
|
|
|
|
self.down2 = down(128, 256)
|
|
|
|
self.down3 = down(256, 512)
|
2017-08-17 13:33:47 +00:00
|
|
|
self.down4 = down(512, 512)
|
|
|
|
self.up1 = up(1024, 256)
|
|
|
|
self.up2 = up(512, 128)
|
|
|
|
self.up3 = up(256, 64)
|
2017-08-16 12:24:29 +00:00
|
|
|
self.up4 = up(128, 64)
|
|
|
|
self.outc = outconv(64, n_classes)
|
|
|
|
|
|
|
|
def forward(self, x):
|
|
|
|
x1 = self.inc(x)
|
|
|
|
x2 = self.down1(x1)
|
|
|
|
x3 = self.down2(x2)
|
|
|
|
x4 = self.down3(x3)
|
|
|
|
x5 = self.down4(x4)
|
|
|
|
x = self.up1(x5, x4)
|
|
|
|
x = self.up2(x, x3)
|
|
|
|
x = self.up3(x, x2)
|
|
|
|
x = self.up4(x, x1)
|
|
|
|
x = self.outc(x)
|
2018-11-10 22:42:16 +00:00
|
|
|
return F.sigmoid(x)
|