class_docstr: Basic Inference Task Helper
class_docstr_tok: ["Basic","Inference","Task","Helper"]
code: def _get_network(self, device, data):
      path = self.get_path()
      logger.info(f"Infer model path: {path}")
  
      if data and self._config.get("model_filename"):
          model_filename = data.get("model_filename")
          model_filename = (
              model_filename
              if isinstance(model_filename, str)
              else model_filename[0]
          )
          user_path = os.path.join(
              os.path.dirname(self.path[0]), model_filename
          )
          if user_path and os.path.exists(user_path):
              path = user_path
              logger.info(
                  f"Using <User> provided model_file: {user_path}"
              )
          else:
              logger.info(
                  f"Ignoring <User> provided model_file (not valid): {user_path}"
              )
  
      if not path and not self.network:
          if self.type == InferType.SCRIBBLES:
              return None
  
          raise MONAILabelException(
              MONAILabelError.INFERENCE_ERROR,
              f"Model Path ({self.path}) does not exist/valid",
          )
  
      cached = self._networks.get(device)
      statbuf = os.stat(path) if path else None
      network = None
      if cached:
          if statbuf and statbuf.st_mtime == cached[1]:
              network = cached[0]
          elif statbuf:
              logger.warning(
                  f"Reload model from cache.  Prev ts: {cached[1]}; Current ts: {statbuf.st_mtime}"
              )
  
      if network is None:
          if self.network:
              network = copy.deepcopy(self.network)
              network.to(torch.device(device))
  
              if path:
                  checkpoint = torch.load(
                      path, map_location=torch.device(device)
                  )
                  model_state_dict = checkpoint.get(
                      self.model_state_dict, checkpoint
                  )
  
                  if set(self.network.state_dict().keys()) != set(
                      checkpoint.keys()
                  ):
                      logger.warning(
                          f"Checkpoint keys don't match network.state_dict()! Items that exist in only one dict"
                          f" but not in the other: {set(self.network.state_dict().keys()) ^ set(checkpoint.keys())}"
                      )
                      logger.warning(
                          "The run will now continue unless load_strict is set to True. "
                          "If loading fails or the network behaves abnormally, please check the loaded weights"
                      )
                  network.load_state_dict(
                      model_state_dict, strict=self.load_strict
                  )
          else:
              network = torch.jit.load(
                  path, map_location=torch.device(device)
              )
  
          if self.train_mode:
              network.train()
          else:
              network.eval()
          self._networks[device] = (
              network,
              statbuf.st_mtime if statbuf else 0,
          )
  
      return network
  
imports: import copy
  import logging
  import os
  import time
  from abc import abstractmethod
  from enum import Enum
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from monai.data import decollate_batch
  from monai.inferers import Inferer, SimpleInferer, SlidingWindowInferer
  from monai.utils import deprecated
  from monailabel.interfaces.exception import MONAILabelError, MONAILabelException
  from monailabel.interfaces.tasks.infer_v2 import InferTask, InferType
  from monailabel.interfaces.utils.transform import dump_data, run_transforms
  from monailabel.transform.cache import CacheTransformDatad
  from monailabel.transform.writer import ClassificationWriter, DetectionWriter, Writer
  from monailabel.utils.others.generic import device_list, device_map, name_to_device
label_desc: Use image node_id 17 for calling the BasicInferTask obj's underlying member method code with example usage: obj._get_network(device, data) and returns: network, None