code: def process_tensorboard_in_callbacks(
      callbacks, mode="train", rank=None
  ):
      import tensorflow as tf
  
      class EpochCopyCallback(tf.keras.callbacks.Callback):
          def __init__(self, local_dir, remote_dir, rank=None):
              super(EpochCopyCallback, self).__init__()
              self.local_dir = local_dir
              self.remote_dir = remote_dir
              self.rank = rank
  
          def on_epoch_end(self, epoch, logs=None):
              if self.rank is not None:
                  if self.rank == 0:
                      put_local_dir_tree_to_remote(
                          self.local_dir, self.remote_dir
                      )
  
      class TrainBatchCopyCallback(tf.keras.callbacks.Callback):
          def __init__(self, local_dir, remote_dir, freq, rank=None):
              super(TrainBatchCopyCallback, self).__init__()
              self.local_dir = local_dir
              self.remote_dir = remote_dir
              self.freq = freq
              self.rank = rank
  
          def on_train_batch_end(self, batch, logs=None):
              if self.rank is not None:
                  if self.rank == 0:
                      if batch % self.freq == 0:
                          put_local_dir_tree_to_remote(
                              self.local_dir, self.remote_dir
                          )
  
      class BatchCopyCallback(tf.keras.callbacks.Callback):
          def __init__(self, local_dir, remote_dir, freq, rank=None):
              super(BatchCopyCallback, self).__init__()
              self.local_dir = local_dir
              self.remote_dir = remote_dir
              self.freq = freq
              self.rank = rank
  
          def on_test_batch_end(self, batch, logs=None):
              if self.rank is not None:
                  if self.rank == 0:
                      if batch % self.freq == 0:
                          put_local_dir_tree_to_remote(
                              self.local_dir, self.remote_dir
                          )
  
      tensorboard = get_specific_object_from_callbacks(
          tf.keras.callbacks.TensorBoard, callbacks
      )
      if tensorboard:
          original_log_dir = tensorboard.log_dir
          replaced_log_dir = get_replaced_path(original_log_dir)
          tensorboard.log_dir = replaced_log_dir
  
          if tensorboard.update_freq == "epoch":
              # create copy callback for epoch
              copy_callback = EpochCopyCallback(
                  replaced_log_dir, original_log_dir, rank
              )
          else:
              # to avoid frequent copy, set update freq > 10
              update_freq = (
                  tensorboard.update_freq
                  if tensorboard.update_freq > 10
                  else 10
              )
              if mode == "fit":
                  # create copy callback for batch
                  copy_callback = TrainBatchCopyCallback(
                      replaced_log_dir,
                      original_log_dir,
                      update_freq,
                      rank,
                  )
              else:
                  copy_callback = BatchCopyCallback(
                      replaced_log_dir,
                      original_log_dir,
                      update_freq,
                      rank,
                  )
          callbacks.append(copy_callback)
          return replaced_log_dir
      return None
  
imports: from contextlib import closing
  import socket
  import sys
  import tempfile
  import shutil
  from bigdl.dllib.utils import log4Error
  from bigdl.dllib.utils.common import callBigDlFunc
  from bigdl.dllib.utils.file_utils import get_file_list, is_local_path
  from bigdl.orca.data import SparkXShards
  from bigdl.orca.data.utils import get_size
  from bigdl.orca.data.file import put_local_dir_tree_to_remote, put_local_file_to_remote, get_remote_file_to_local, get_remote_dir_to_local
  from bigdl.dllib.utils.utils import convert_row_to_numpy
  from functools import partial
  import numpy
  from bigdl.orca.common import SafePickle
  import os
  import subprocess
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 35 for calling a global function with example usage: process_tensorboard_in_callbacks(callbacks, mode, rank) and returns: None, replaced_log_dir