code: def count_parameters(
      model: nn.Module,
      keys: Optional[Sequence[str]] = None,
      human_friendly: bool = False,
  ) -> Dict[str, int]:
      """
      Count number of total and trainable parameters of a model
      :param model: A model
      :param keys: Optional list of top-level blocks
      :param human_friendly: If True, outputs human-friendly number of paramters: 13.3M, 124K
      :return: Tuple (total, trainable)
      """
      if keys is None:
          keys = [key for key, child in model.named_children()]
      total = int(sum(p.numel() for p in model.parameters()))
      trainable = int(
          sum(p.numel() for p in model.parameters() if p.requires_grad)
      )
      parameters = {"total": total, "trainable": trainable}
  
      for key in keys:
          try:
              if (
                  hasattr(model, key)
                  and model.__getattr__(key) is not None
              ):
                  parameters[key] = int(
                      sum(
                          p.numel()
                          for p in model.__getattr__(key).parameters()
                      )
                  )
          except AttributeError:
              pass
  
      if human_friendly:
          for key in parameters.keys():
              parameters[key] = int_to_string_human_friendly(
                  parameters[key]
              )
      return parameters
  
imports: import collections
  import dataclasses
  import functools
  import warnings
  import logging
  from typing import Optional, Sequence, Union, Dict, List, Any, Iterable, Callable
  import numpy
  import torch
  from torch import nn, Tensor
  from torch.utils.data import Dataset, ConcatDataset
  from torch.utils.data.dataloader import default_collate
  from .support import pytorch_toolbelt_deprecated
label_desc: Use image node_id 11 for calling a global function with example usage: count_parameters(model, keys, human_friendly) and returns: parameters