| 116 | return ModuleList(branches) |
| 117 | |
| 118 | def _make_fuse_layers(self): |
| 119 | if self.num_branches == 1: |
| 120 | return None |
| 121 | |
| 122 | num_branches = self.num_branches |
| 123 | in_channels = self.in_channels |
| 124 | fuse_layers = [] |
| 125 | num_out_branches = num_branches if self.multiscale_output else 1 |
| 126 | for i in range(num_out_branches): |
| 127 | fuse_layer = [] |
| 128 | for j in range(num_branches): |
| 129 | if j > i: |
| 130 | fuse_layer.append( |
| 131 | nn.Sequential( |
| 132 | build_conv_layer(self.conv_cfg, |
| 133 | in_channels[j], |
| 134 | in_channels[i], |
| 135 | kernel_size=1, |
| 136 | stride=1, |
| 137 | padding=0, |
| 138 | bias=False), |
| 139 | build_norm_layer(self.norm_cfg, in_channels[i])[1], |
| 140 | nn.Upsample(scale_factor=2**(j - i), |
| 141 | mode='nearest'))) |
| 142 | elif j == i: |
| 143 | fuse_layer.append(None) |
| 144 | else: |
| 145 | conv_downsamples = [] |
| 146 | for k in range(i - j): |
| 147 | if k == i - j - 1: |
| 148 | conv_downsamples.append( |
| 149 | nn.Sequential( |
| 150 | build_conv_layer(self.conv_cfg, |
| 151 | in_channels[j], |
| 152 | in_channels[i], |
| 153 | kernel_size=3, |
| 154 | stride=2, |
| 155 | padding=1, |
| 156 | bias=False), |
| 157 | build_norm_layer(self.norm_cfg, |
| 158 | in_channels[i])[1])) |
| 159 | else: |
| 160 | conv_downsamples.append( |
| 161 | nn.Sequential( |
| 162 | build_conv_layer(self.conv_cfg, |
| 163 | in_channels[j], |
| 164 | in_channels[j], |
| 165 | kernel_size=3, |
| 166 | stride=2, |
| 167 | padding=1, |
| 168 | bias=False), |
| 169 | build_norm_layer(self.norm_cfg, |
| 170 | in_channels[j])[1], |
| 171 | nn.ReLU(inplace=False))) |
| 172 | fuse_layer.append(nn.Sequential(*conv_downsamples)) |
| 173 | fuse_layers.append(nn.ModuleList(fuse_layer)) |
| 174 | |
| 175 | return nn.ModuleList(fuse_layers) |