code: def load_custom_pretrained(
      model: nn.Module,
      pretrained_cfg: Optional[Dict] = None,
      load_fn: Optional[Callable] = None,
  ):
      r"""Loads a custom (read non .pth) weight file
  
      Downloads checkpoint file into cache-dir like torch.hub based loaders, but calls
      a passed in custom load fun, or the `load_pretrained` model member fn.
  
      If the object is already present in `model_dir`, it's deserialized and returned.
      The default value of `model_dir` is ``<hub_dir>/checkpoints`` where
      `hub_dir` is the directory returned by :func:`~torch.hub.get_dir`.
  
      Args:
          model: The instantiated model to load weights into
          pretrained_cfg (dict): Default pretrained model cfg
          load_fn: An external standalone fn that loads weights into provided model, otherwise a fn named
              'laod_pretrained' on the model will be called if it exists
      """
      pretrained_cfg = pretrained_cfg or getattr(
          model, "pretrained_cfg", None
      )
      if not pretrained_cfg:
          _logger.warning(
              "Invalid pretrained config, cannot load weights."
          )
          return
  
      load_from, pretrained_loc = _resolve_pretrained_source(
          pretrained_cfg
      )
      if not load_from:
          _logger.warning(
              "No pretrained weights exist for this model. Using random initialization."
          )
          return
      if load_from == "hf-hub":
          _logger.warning(
              "Hugging Face hub not currently supported for custom load pretrained models."
          )
      elif load_from == "url":
          pretrained_loc = download_cached_file(
              pretrained_loc,
              check_hash=_CHECK_HASH,
              progress=_DOWNLOAD_PROGRESS,
          )
  
      if load_fn is not None:
          load_fn(model, pretrained_loc)
      elif hasattr(model, "load_pretrained"):
          model.load_pretrained(pretrained_loc)
      else:
          _logger.warning(
              "Valid function to load pretrained weights is not available, using random initialization."
          )
  
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 4 for calling a global function with example usage: load_custom_pretrained(model, pretrained_cfg, load_fn) without return types