import torch


def _find_output_channels(module: torch.nn.Module) -> int:
    """Get the number of output channels of a module.

    Note: This may break if the module does not apply layers in the order in
    which they were assigned to the module (this is because of pytorch's
    dynamic computation graph).

    Parameters
    ----------
    module : torch.nn.Module

    Raises
    ------
    TypeError
        If your module does not contain any convolutional layers.

    Returns
    -------
    int
        The output channels.
    """

    output_channels = None
    # This may break if the order of module.modules() doesn't match the order
    # in which layers are applied to the data
    for layer in module.modules():
        if hasattr(layer, "out_channels"):
            output_channels = layer.out_channels

    if output_channels is None:
        raise TypeError("Your module doesn't seem to have any conv layers.")

    return output_channels