| 104 | |
| 105 | |
| 106 | class _DecoderBlock(nn.Sequential): |
| 107 | |
| 108 | def __init__( |
| 109 | self, |
| 110 | layers: int, |
| 111 | num_features: int, |
| 112 | in_channels: int, |
| 113 | out_channels: int, |
| 114 | dropout_prob: float = 0.0, |
| 115 | act: str | tuple = ("relu", {"inplace": True}), |
| 116 | norm: str | tuple = "batch", |
| 117 | kernel_size: int = 3, |
| 118 | same_padding: bool = False, |
| 119 | ) -> None: |
| 120 | """ |
| 121 | Args: |
| 122 | layers: number of layers in the block. |
| 123 | num_features: number of internal features used. |
| 124 | in_channels: number of the input channel. |
| 125 | out_channels: number of the output channel. |
| 126 | dropout_prob: dropout rate after each dense layer. |
| 127 | act: activation type and arguments. Defaults to relu. |
| 128 | norm: feature normalization type and arguments. Defaults to batch norm. |
| 129 | kernel_size: size of the kernel for >1 convolutions (dependent on mode) |
| 130 | same_padding: whether to do padding for >1 convolutions to ensure |
| 131 | the output size is the same as the input size. |
| 132 | """ |
| 133 | super().__init__() |
| 134 | |
| 135 | conv_type: Callable = Conv[Conv.CONV, 2] |
| 136 | |
| 137 | padding: int = kernel_size // 2 if same_padding else 0 |
| 138 | |
| 139 | self.add_module( |
| 140 | "conva", conv_type(in_channels, in_channels // 4, kernel_size=kernel_size, padding=padding, bias=False) |
| 141 | ) |
| 142 | |
| 143 | _in_channels = in_channels // 4 |
| 144 | for i in range(layers): |
| 145 | layer = _DenseLayerDecoder( |
| 146 | num_features, |
| 147 | _in_channels, |
| 148 | out_channels, |
| 149 | dropout_prob, |
| 150 | act=act, |
| 151 | norm=norm, |
| 152 | kernel_size=kernel_size, |
| 153 | padding=padding, |
| 154 | ) |
| 155 | _in_channels += out_channels |
| 156 | self.add_module(f"denselayerdecoder{i + 1}", layer) |
| 157 | |
| 158 | trans = _Transition(_in_channels, act=act, norm=norm) |
| 159 | self.add_module("bna_block", trans) |
| 160 | self.add_module("convf", conv_type(_in_channels, _in_channels, kernel_size=1, bias=False)) |
| 161 | |
| 162 | |
| 163 | class _DenseLayer(nn.Sequential): |
no outgoing calls
no test coverage detected
searching dependent graphs…