I have some error with my gan model

Somsak_Paerattanakul: <p>I try to add FCA net to my model but had some error like this<br>
anyone can tell me which line of my code are wrong.<br>
thank you.</p>
<p>RuntimeError: Given groups=1, weight of size 64 3 4 4, expected input[10, 64, 256, 256] to have 3 channels, but got 64 channels instead</p>

Somsak_Paerattanakul: <p>class UNetDown(nn.Module):<br>
def <strong>init</strong>(self, in_size, out_size, normalize=True, dropout=0.0):<br>
super(UNetDown, self).<strong>init</strong>()<br>
layers = [nn.Conv2d(in_size, out_size, 4, 2, 1, bias=False)]<br>
if normalize:<br>
layers.append(nn.InstanceNorm2d(out_size))<br>
layers.append(nn.ReLU(inplace=True))<br>
if dropout:<br>
layers.append(nn.Dropout(dropout))<br>
self.model = nn.Sequential(*layers)</p>
<pre><code>def forward(self, x):
    return self.model(x)
</code></pre>
<p>class UNetUp(nn.Module):<br>
def <strong>init</strong>(self, in_size, out_size, dropout=0.0):<br>
super(UNetUp, self).<strong>init</strong>()<br>
layers = [nn.ConvTranspose2d(in_size, out_size, 4, 2, 1, bias=False),<br>
nn.InstanceNorm2d(out_size),<br>
nn.ReLU(inplace=True)]<br>
if dropout:<br>
layers.append(nn.Dropout(dropout))</p>
<pre><code>    self.model = nn.Sequential(*layers)

def forward(self, x, skip_input):
    x = self.model(x)
    x = torch.cat((x, skip_input), 1)

    return x
</code></pre>
<p>class GeneratorUNet(nn.Module):<br>
def <strong>init</strong>(self, in_channels=3, out_channels=1):<br>
super(GeneratorUNet, self).<strong>init</strong>()<br>
self.size1 = nn.AvgPool2d(1, stride=8)<br>
self.size3 = nn.AvgPool2d(1, stride=4)<br>
self.size4 = nn.AvgPool2d(1, stride=2)<br>
self.convinput = nn.Conv2d(3, 64, kernel_size=3,padding=1, bias=False)<br>
self.factor_in=FCANet(64,64)<br>
self.conva=nn.Conv2d(3, 64, kernel_size=3,padding=1, bias=False)<br>
self.factor_a= FCANet(64,64)<br>
self.convb=nn.Conv2d(3, 64, kernel_size=3,padding=1, bias=False)<br>
self.factor_b= FCANet(64,64)<br>
self.convc=nn.Conv2d(3, 64, kernel_size=3,padding=1, bias=False)<br>
self.factor_c=FCANet(64,64)</p>
<pre><code>    self.down1 = UNetDown(in_channels, 64, normalize=False)
    self.down2 = UNetDown(64, 128)
    self.c2 = FCANet(128,128)
    self.down3 = UNetDown(128, 256)
    self.c3 = FCANet(256,256)
    self.down4 = UNetDown(256, 512, dropout=0.0)
    self.c4 = FCANet(512,512)
    self.down5 = UNetDown(512, 512, dropout=0.0)
    self.c5 = FCANet(512,512)
    self.down6 = UNetDown(512, 512, dropout=0.0)
    self.c6 = FCANet(512,512)
    self.down7 = UNetDown(512, 512, dropout=0.0)
    self.c7 = FCANet(512,512)
    self.down8 = UNetDown(512, 512, normalize=False, dropout=0.0)
    self.up1 = UNetUp(512, 512, dropout=0.0)
    self.up2 = UNetUp(1024, 512, dropout=0.0)
    self.up3 = UNetUp(1024, 512, dropout=0.0)
    self.up4 = UNetUp(1024, 512, dropout=0.0)
    self.up5 = UNetUp(1024, 256)
    self.up6 = UNetUp(512, 128)
    self.up7 = UNetUp(256, 64)

    self.final = nn.Sequential(
        nn.Upsample(scale_factor=2),
        nn.ZeroPad2d((1, 0, 1, 0)),
        nn.Conv2d(128, out_channels, 4, padding=1,),
        nn.Dropout(0.0),
        nn.Tanh()
    )


def forward(self, input):
    a=self.size1(input)
    b=self.size3(input)
    c=self.size4(input)
    input= self.convinput(input)
    input = self.factor_in(input)
    a = self.conva(a) 
    a = self.factor_a(a)
    a=nn.functional.interpolate(a, size=256, mode='bilinear', align_corners=True)    
    b = self.convb(b)
    b = self.factor_b(b)
    b=nn.functional.interpolate(b, size=256, mode='bilinear', align_corners=True)    
    c = self.convc(c)
    c = self.factor_c(c)
    c=nn.functional.interpolate(c, size=256, mode='bilinear', align_corners=True)
    x=(input+a+b+c)
    # U-Net generator with skip connections from encoder to decoder
    d1 = self.down1(x)
    d2 = self.down2(d1)
    d3 = self.down3(d2)
    d4 = self.down4(d3)
    d5 = self.down5(d4)
    d6 = self.down6(d5)
    d7 = self.down7(d6)
    d8 = self.down8(d7)

    u1 = self.up1(d8, d7)
    u2 = self.up2(u1, d6)
    u3 = self.up3(u2, d5)
    u4 = self.up4(u3, d4)
    u5 = self.up5(u4, d3)
    u6 = self.up6(u5, d2)
    u7 = self.up7(u6, d1)

    return self.final(u7)
</code></pre>
<p>class FCANet(nn.Module):<br>
def <strong>init</strong>(self, in_channels, out_channels):<br>
super(FCANet, self).<strong>init</strong>()<br>
inter_channels = in_channels // 4<br>
self.conv5a = nn.Sequential(nn.Conv2d(in_channels, inter_channels, 3, padding=1, bias=False),<br>
nn.BatchNorm2d(inter_channels),<br>
nn.ReLU())<br>
self.conv5c = nn.Sequential(nn.Conv2d(in_channels, inter_channels, 3, padding=1, bias=False),<br>
nn.BatchNorm2d(inter_channels),<br>
nn.ReLU())<br>
self.sa = non_bottleneck_1d(inter_channels, 0.3, 2)<br>
self.sc = CAM_Module(inter_channels)<br>
self.conv51 = nn.Sequential(nn.Conv2d(inter_channels, inter_channels, 3, padding=1, bias=False),<br>
nn.BatchNorm2d(inter_channels),<br>
nn.ReLU())<br>
self.conv52 = nn.Sequential(nn.Conv2d(inter_channels, inter_channels, 3, padding=1, bias=False),<br>
nn.BatchNorm2d(inter_channels),<br>
nn.ReLU())<br>
self.conv8 = nn.Sequential(nn.Dropout2d(0.1, False), nn.Conv2d(inter_channels, out_channels, 1))</p>
<pre><code>def forward(self, x):
    feat1 = self.conv5a(x)
    sa_feat = self.sa(feat1)
    sa_conv = self.conv51(sa_feat)
    feat2 = self.conv5c(x)
    sc_feat = self.sc(feat2)
    sc_conv = self.conv52(sc_feat)
    feat_sum = 0.3*sa_conv+0.7*sc_conv
    sasc_output = self.conv8(feat_sum)
    return sasc_output</code></pre>

Isaac_Kargar: <p>Based on the error, you need to check the shape of tensor. Please put your code in a clean way between two “```”. We can help you more then</p>