| 296 | return x4 |
| 297 | |
| 298 | class Exp2_Decoder29(nn.Module): |
| 299 | def __init__(self, num_classes, channels): |
| 300 | super().__init__() |
| 301 | channels4,channels8,channels16=channels["4"],channels["8"],channels["16"] |
| 302 | self.head16=ConvBnAct(channels16, 256, 1) |
| 303 | self.head8=ConvBnAct(channels8, 256, 1) |
| 304 | self.head4=ConvBnAct(channels4, 16, 1) |
| 305 | self.conv8=ConvBnAct(256,128,3,1,1) |
| 306 | self.conv4=ConvBnAct(128+16,128,3,1,1) |
| 307 | self.classifier=nn.Conv2d(128, num_classes, 1) |
| 308 | |
| 309 | def forward(self, x): |
| 310 | x4, x8, x16=x["4"], x["8"],x["16"] |
| 311 | x16=self.head16(x16) |
| 312 | x8=self.head8(x8) |
| 313 | x4=self.head4(x4) |
| 314 | x16 = F.interpolate(x16, size=x8.shape[-2:], mode='bilinear', align_corners=False) |
| 315 | x8= x8 + x16 |
| 316 | x8=self.conv8(x8) |
| 317 | x8 = F.interpolate(x8, size=x4.shape[-2:], mode='bilinear', align_corners=False) |
| 318 | x4=torch.cat((x8,x4),dim=1) |
| 319 | x4=self.conv4(x4) |
| 320 | x4=self.classifier(x4) |
| 321 | return x4 |
| 322 | |
| 323 | def generate_stage(num,block_fun): |
| 324 | blocks=[] |