# full assembly of the sub-parts to form the complete net

from .unet_parts import *
import numpy as np
from .base_network import NetworkBase

class UNet(NetworkBase):
    def __init__(self, n_channels = 4, n_classes = 3):
        super(UNet, self).__init__()
        self._name = 'unet_generator'
        self.inc = inconv(n_channels, 64)
        self.down1 = down(64, 128)
        self.down2 = down(128, 256)
        self.down3 = down(256, 512)
        self.down4 = down(512, 512)
        self.up1 = up(1024, 256)
        self.up2 = up(512, 128)
        self.up3 = up(256, 64)
        self.up4 = up(128, 64)
        self.outc = outconv(64, n_classes)

    def forward(self, x_img, x_real_heatmap, x_desired_heatmap, desired_cond, fixed_noise):
        x_real_heatmap = x_real_heatmap.view(-1,1,128,128)
        x_input = torch.cat([x_img, x_real_heatmap], dim=1)
        # desired_cond = desired_cond.unsqueeze(2).unsqueeze(3)
        # desired_cond = desired_cond.expand(desired_cond.size(0), desired_cond.size(1), x_img.size(2), x_img.size(3))
        
        #x_input = torch.cat([x_img, desired_cond], dim=1)
        x1 = self.inc(x_input)
        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)
        return x, x1