Пример #1
0
def get_conv_layer(
    spatial_dims: int,
    in_channels: int,
    out_channels: int,
    kernel_size: Union[Sequence[int], int] = 3,
    stride: Union[Sequence[int], int] = 1,
    act: Optional[Union[Tuple, str]] = Act.PRELU,
    norm: Union[Tuple, str] = Norm.INSTANCE,
    bias: bool = False,
    conv_only: bool = True,
    is_transposed: bool = False,
    num_groups: int = 1,
    is_prunable: bool = False,
):
    padding = get_padding(kernel_size, stride)
    output_padding = None
    if is_transposed:
        output_padding = get_output_padding(kernel_size, stride, padding)
    return Convolution(
        spatial_dims,
        in_channels,
        out_channels,
        strides=stride,
        kernel_size=kernel_size,
        act=act,
        norm=norm,
        groups=num_groups,
        bias=bias,
        conv_only=conv_only,
        is_transposed=is_transposed,
        is_prunable=is_prunable,
        padding=padding,
        output_padding=output_padding,
    )
Пример #2
0
from monai.networks import eval_mode
from monai.networks.blocks.dynunet_block import UnetBasicBlock, UnetResBlock, UnetUpBlock, get_padding
from tests.utils import test_script_save

TEST_CASE_RES_BASIC_BLOCK = []
for spatial_dims in range(2, 4):
    for kernel_size in [1, 3]:
        for stride in [1, 2]:
            for norm_name in [("GROUP", {
                    "num_groups": 16
            }), ("batch", {
                    "track_running_stats": False
            }), "instance"]:
                for in_size in [15, 16]:
                    padding = get_padding(kernel_size, stride)
                    if not isinstance(padding, int):
                        padding = padding[0]
                    out_size = int(
                        (in_size + 2 * padding - kernel_size) / stride) + 1
                    test_case = [
                        {
                            "spatial_dims":
                            spatial_dims,
                            "in_channels":
                            16,
                            "out_channels":
                            16,
                            "kernel_size":
                            kernel_size,
                            "norm_name":