| 111 | """ |
| 112 | |
| 113 | def __init__( |
| 114 | self, |
| 115 | spatial_dims: int, |
| 116 | encoder_channels: Sequence[int], |
| 117 | decoder_channels: Sequence[int], |
| 118 | act: str | tuple, |
| 119 | norm: str | tuple, |
| 120 | dropout: float | tuple, |
| 121 | bias: bool, |
| 122 | upsample: str, |
| 123 | pre_conv: str | None, |
| 124 | interp_mode: str, |
| 125 | align_corners: bool | None, |
| 126 | is_pad: bool, |
| 127 | ): |
| 128 | super().__init__() |
| 129 | if len(encoder_channels) < 2: |
| 130 | raise ValueError("the length of `encoder_channels` should be no less than 2.") |
| 131 | if len(decoder_channels) != len(encoder_channels) - 1: |
| 132 | raise ValueError("`len(decoder_channels)` should equal to `len(encoder_channels) - 1`.") |
| 133 | |
| 134 | in_channels = [encoder_channels[-1]] + list(decoder_channels[:-1]) |
| 135 | skip_channels = list(encoder_channels[1:-1][::-1]) + [0] |
| 136 | halves = [True] * (len(skip_channels) - 1) |
| 137 | halves.append(False) |
| 138 | blocks = [] |
| 139 | for in_chn, skip_chn, out_chn, halve in zip(in_channels, skip_channels, decoder_channels, halves): |
| 140 | blocks.append( |
| 141 | UpCat( |
| 142 | spatial_dims=spatial_dims, |
| 143 | in_chns=in_chn, |
| 144 | cat_chns=skip_chn, |
| 145 | out_chns=out_chn, |
| 146 | act=act, |
| 147 | norm=norm, |
| 148 | dropout=dropout, |
| 149 | bias=bias, |
| 150 | upsample=upsample, |
| 151 | pre_conv=pre_conv, |
| 152 | interp_mode=interp_mode, |
| 153 | align_corners=align_corners, |
| 154 | halves=halve, |
| 155 | is_pad=is_pad, |
| 156 | ) |
| 157 | ) |
| 158 | self.blocks = nn.ModuleList(blocks) |
| 159 | |
| 160 | def forward(self, features: list[torch.Tensor], skip_connect: int = 4): |
| 161 | skips = features[:-1][::-1] |