Helper for initializing ConstantPadNd with SAME padding similar to Tensorflow. Uses output of _get_same_padding_conv_nd() to get the padding size. This function is generalized for MONAI's N-Dimensional spatial operations (e.g. Conv1D, Conv2D, Conv3D) Args: conv_op: nn.Conv
(conv_op: nn.Conv1d | nn.Conv2d | nn.Conv3d, image_size: list[int])
| 848 | |
| 849 | |
| 850 | def _make_same_padder(conv_op: nn.Conv1d | nn.Conv2d | nn.Conv3d, image_size: list[int]): |
| 851 | """ |
| 852 | Helper for initializing ConstantPadNd with SAME padding similar to Tensorflow. |
| 853 | Uses output of _get_same_padding_conv_nd() to get the padding size. |
| 854 | |
| 855 | This function is generalized for MONAI's N-Dimensional spatial operations (e.g. Conv1D, Conv2D, Conv3D) |
| 856 | |
| 857 | Args: |
| 858 | conv_op: nn.ConvNd operation to extract parameters for op from |
| 859 | image_size: input image/feature spatial size |
| 860 | |
| 861 | Returns: |
| 862 | If padding required then nn.ConstandNd() padder initialized to paddings otherwise nn.Identity() |
| 863 | """ |
| 864 | # calculate padding required |
| 865 | padding: list[int] = _get_same_padding_conv_nd(image_size, conv_op.kernel_size, conv_op.dilation, conv_op.stride) |
| 866 | |
| 867 | # initialize and return padder |
| 868 | padder = Pad["constantpad", len(padding) // 2] |
| 869 | if sum(padding) > 0: |
| 870 | return padder(padding=padding, value=0.0) |
| 871 | return nn.Identity() |
| 872 | |
| 873 | |
| 874 | def _round_filters(filters: int, width_coefficient: float | None, depth_divisor: float) -> int: |
no test coverage detected
searching dependent graphs…