def nchw2nlc2nchw(module, x, contiguous=False, **kwargs):
    """Flatten [N, C, H, W] shape tensor `x` to [N, L, C] shape tensor. Use the
    reshaped tensor as the input of `module`, and the convert the output of
    `module`, whose shape is.

    [N, L, C], to [N, C, H, W].

    Args:
        module (Callable): A callable object the takes a tensor
            with shape [N, L, C] as input.
        x (Tensor): The input tensor of shape [N, C, H, W].
                contiguous:
        contiguous (Bool): Whether to make the tensor contiguous
            after each shape transform.

    Returns:
        Tensor: The output tensor of shape [N, C, H, W].

    Example:
        >>> import torch
        >>> import torch.nn as nn
        >>> norm = nn.LayerNorm(4)
        >>> feature_map = torch.rand(4, 4, 5, 5)
        >>> output = nchw2nlc2nchw(norm, feature_map)
    """
    B, C, H, W = x.shape
    if not contiguous:
        x = x.flatten(2).transpose(1, 2)
        x = module(x, **kwargs)
        x = x.transpose(1, 2).reshape(B, C, H, W)
    else:
        x = x.flatten(2).transpose(1, 2).contiguous()
        x = module(x, **kwargs)
        x = x.transpose(1, 2).reshape(B, C, H, W).contiguous()
    return x