def count_parameters(model, tunable_only: bool = True) -> int:
    """ Count the number of parameters in the given model.

    Parameters
    ----------
    model : torch.nn.Module
        PyTorch model (deep network)
    tunable_only : bool, optional
        Count only tunable network parameters

    References
    ----------
    https://stackoverflow.com/questions/49201236/check-the-total-number-of-parameters-in-a-pytorch-model
    """
    if tunable_only:
        return sum(p.numel() for p in model.parameters() if p.requires_grad)
    else:
        return sum(p.numel() for p in model.parameters())