code: def get_writer(log_dir, logger, visdom=False, visdom_params=None):
      """
      Get the writer assigned to the given log directory.
      If the writer doesn't exist it will be created, and a reference to the logger added.
  
      Args:
          log_dir (str): the log directory
          logger: the object requesting the writer. That object should call `close_writer` when its finished
          visdom (bool): if true VisdomWriter is returned instead of tensorboard SummaryWriter
          visdom_params (VisdomParams): Visdom parameter settings object, uses default if None
  
      Returns:
          the `SummaryWriter` or `VisdomWriter` object
      """
      import tensorboardX
      from tensorboardX import SummaryWriter
      import sys
      import errno
  
      kwargs = {}
      if sys.version_info[0] >= 3:
          kwargs["exist_ok"] = True
  
      writer_key = "writer"
      if visdom:
          writer_key = "writer_visdom"
  
      if (
          log_dir not in __writers__
          or writer_key not in __writers__[log_dir]
      ):
          if visdom:
              w = tensorboardX.torchvis.VisdomWriter()
              from visdom import Visdom
  
              try:
                  os.makedirs(log_dir, **kwargs)
              except OSError as exc:
                  if exc.errno == errno.EEXIST and os.path.isdir(
                      log_dir
                  ):
                      pass
                  else:
                      raise exc
              if visdom_params is None:
                  visdom_params = VisdomParams()
                  visdom_params.LOG_TO_FILENAME = os.path.join(
                      log_dir, "log.log"
                  )
              w.vis = Visdom(**visdom_params.__to_dict__())
          else:
              w = SummaryWriter(log_dir=log_dir)
          __writers__[log_dir] = {writer_key: w, "references": set()}
  
      __writers__[log_dir]["references"].add(logger)
      return __writers__[log_dir][writer_key]
  
imports: import copy
  import os
  import warnings
  import torch
  import torch.nn.functional
  import torchbearer
  from torchbearer.callbacks import Callback
label_desc: Use image node_id 1 for calling a global function with example usage: get_writer(log_dir, logger, visdom, visdom_params) and returns: __writers__