| 48 | |
| 49 | return out |
| 50 | class MultipleBasicBlock(nn.Module): |
| 51 | |
| 52 | def __init__(self,input_feature, |
| 53 | block, num_blocks, |
| 54 | intermediate_feature = 64, dense = True): |
| 55 | super(MultipleBasicBlock, self).__init__() |
| 56 | self.dense = dense |
| 57 | self.num_block = num_blocks |
| 58 | self.intermediate_feature = intermediate_feature |
| 59 | |
| 60 | self.block1= nn.Sequential(*[ |
| 61 | nn.Conv2d(input_feature, intermediate_feature, |
| 62 | kernel_size=7, stride=1, padding=3, bias=True), |
| 63 | nn.ReLU(inplace=True) |
| 64 | ]) |
| 65 | |
| 66 | # for i in range(1, num_blocks): |
| 67 | self.block2 = block(intermediate_feature, intermediate_feature, dilation = 1) if num_blocks>=2 else None |
| 68 | self.block3 = block(intermediate_feature, intermediate_feature, dilation = 1) if num_blocks>=3 else None |
| 69 | self.block4 = block(intermediate_feature, intermediate_feature, dilation = 1) if num_blocks>=4 else None |
| 70 | self.block5 = nn.Sequential(*[nn.Conv2d(intermediate_feature, 3 , (3, 3), 1, (1, 1))]) |
| 71 | |
| 72 | for m in self.modules(): |
| 73 | if isinstance(m, nn.Conv2d): |
| 74 | n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels |
| 75 | m.weight.data.normal_(0, math.sqrt(2. / n)) |
| 76 | elif isinstance(m, nn.BatchNorm2d): |
| 77 | m.weight.data.fill_(1) |
| 78 | m.bias.data.zero_() |
| 79 | |
| 80 | def forward(self, x): |
| 81 | x = self.block1(x) |
| 82 | x = self.block2(x) if self.num_block>=2 else x |
| 83 | x = self.block3(x) if self.num_block>=3 else x |
| 84 | x = self.block4(x) if self.num_block== 4 else x |
| 85 | x = self.block5(x) |
| 86 | return x |
| 87 | |
| 88 | def MultipleBasicBlock_4(input_feature,intermediate_feature = 64): |
| 89 | model = MultipleBasicBlock(input_feature, |
no outgoing calls
no test coverage detected