code: def load_pretrained(
      model: nn.Module,
      pretrained_cfg: Optional[Dict] = None,
      num_classes: int = 1000,
      in_chans: int = 3,
      filter_fn: Optional[Callable] = None,
      strict: bool = True,
  ):
      """Load pretrained checkpoint
  
      Args:
          model (nn.Module) : PyTorch model module
          pretrained_cfg (Optional[Dict]): configuration for pretrained weights / target dataset
          num_classes (int): num_classes for target model
          in_chans (int): in_chans for target model
          filter_fn (Optional[Callable]): state_dict filter fn for load (takes state_dict, model as args)
          strict (bool): strict load of checkpoint
  
      """
      pretrained_cfg = pretrained_cfg or getattr(
          model, "pretrained_cfg", None
      )
      if not pretrained_cfg:
          raise RuntimeError(
              "Invalid pretrained config, cannot load weights. Use `pretrained=False` for random init."
          )
  
      load_from, pretrained_loc = _resolve_pretrained_source(
          pretrained_cfg
      )
      if load_from == "state_dict":
          _logger.info(f"Loading pretrained weights from state dict")
          state_dict = pretrained_loc  # pretrained_loc is the actual state dict for this override
      elif load_from == "file":
          _logger.info(
              f"Loading pretrained weights from file ({pretrained_loc})"
          )
          if pretrained_cfg.get("custom_load", False):
              model.load_pretrained(pretrained_loc)
              return
          else:
              state_dict = load_state_dict(pretrained_loc)
      elif load_from == "url":
          _logger.info(
              f"Loading pretrained weights from url ({pretrained_loc})"
          )
          if pretrained_cfg.get("custom_load", False):
              pretrained_loc = download_cached_file(
                  pretrained_loc,
                  progress=_DOWNLOAD_PROGRESS,
                  check_hash=_CHECK_HASH,
              )
              model.load_pretrained(pretrained_loc)
              return
          else:
              state_dict = load_state_dict_from_url(
                  pretrained_loc,
                  map_location="cpu",
                  progress=_DOWNLOAD_PROGRESS,
                  check_hash=_CHECK_HASH,
              )
      elif load_from == "hf-hub":
          _logger.info(
              f"Loading pretrained weights from Hugging Face hub ({pretrained_loc})"
          )
          if isinstance(pretrained_loc, (list, tuple)):
              state_dict = load_state_dict_from_hf(*pretrained_loc)
          else:
              state_dict = load_state_dict_from_hf(pretrained_loc)
      else:
          model_name = pretrained_cfg.get("architecture", "this model")
          raise RuntimeError(
              f"No pretrained weights exist for {model_name}. Use `pretrained=False` for random init."
          )
  
      if filter_fn is not None:
          try:
              state_dict = filter_fn(state_dict, model)
          except TypeError as e:
              # for backwards compat with filter fn that take one arg
              state_dict = filter_fn(state_dict)
  
      input_convs = pretrained_cfg.get("first_conv", None)
      if input_convs is not None and in_chans != 3:
          if isinstance(input_convs, str):
              input_convs = (input_convs,)
          for input_conv_name in input_convs:
              weight_name = input_conv_name + ".weight"
              try:
                  state_dict[weight_name] = adapt_input_conv(
                      in_chans, state_dict[weight_name]
                  )
                  _logger.info(
                      f"Converted input conv {input_conv_name} pretrained weights from 3 to {in_chans} channel(s)"
                  )
              except NotImplementedError as e:
                  del state_dict[weight_name]
                  strict = False
                  _logger.warning(
                      f"Unable to convert pretrained {input_conv_name} weights, using random init for this layer."
                  )
  
      classifiers = pretrained_cfg.get("classifier", None)
      label_offset = pretrained_cfg.get("label_offset", 0)
      if classifiers is not None:
          if isinstance(classifiers, str):
              classifiers = (classifiers,)
          if num_classes != pretrained_cfg["num_classes"]:
              for classifier_name in classifiers:
                  # completely discard fully connected if model num_classes doesn't match pretrained weights
                  state_dict.pop(classifier_name + ".weight", None)
                  state_dict.pop(classifier_name + ".bias", None)
              strict = False
          elif label_offset > 0:
              for classifier_name in classifiers:
                  # special case for pretrained weights with an extra background class in pretrained weights
                  classifier_weight = state_dict[
                      classifier_name + ".weight"
                  ]
                  state_dict[
                      classifier_name + ".weight"
                  ] = classifier_weight[label_offset:]
                  classifier_bias = state_dict[
                      classifier_name + ".bias"
                  ]
                  state_dict[
                      classifier_name + ".bias"
                  ] = classifier_bias[label_offset:]
  
      load_result = model.load_state_dict(state_dict, strict=strict)
      if load_result.missing_keys:
          _logger.info(
              f'Missing keys ({", ".join(load_result.missing_keys)}) discovered while loading pretrained weights.'
              f" This is expected if model is being adapted."
          )
      if load_result.unexpected_keys:
          _logger.warning(
              f'Unexpected keys ({", ".join(load_result.unexpected_keys)}) found while loading pretrained weights.'
              f" This may be expected if model is being adapted."
          )
  
imports: import dataclasses
  import logging
  import os
  from copy import deepcopy
  from typing import Optional, Dict, Callable, Any, Tuple
  from torch import nn
  from torch.hub import load_state_dict_from_url
  from timm.models._features import FeatureListNet, FeatureHookNet
  from timm.models._features_fx import FeatureGraphNet
  from timm.models._helpers import load_state_dict
  from timm.models._hub import has_hf_hub, download_cached_file, check_cached_file, load_state_dict_from_hf
  from timm.models._manipulate import adapt_input_conv
  from timm.models._pretrained import PretrainedCfg
  from timm.models._prune import adapt_model_from_file
  from timm.models._registry import get_pretrained_cfg
label_desc: Use image node_id 5 for calling a global function with example usage: load_pretrained(model, pretrained_cfg, num_classes, in_chans, filter_fn, strict) without return types