code: def fit(
      network,
      train_op,
      cost,
      X_train,
      y_train,
      acc=None,
      batch_size=100,
      n_epoch=100,
      print_freq=5,
      X_val=None,
      y_val=None,
      eval_train=True,
      tensorboard_dir=None,
      tensorboard_epoch_freq=5,
      tensorboard_weight_histograms=True,
      tensorboard_graph_vis=True,
  ):
      """Training a given non time-series network by the given cost function, training data, batch_size, n_epoch etc.
  
      - MNIST example click `here <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_mnist_simple.py>`_.
      - In order to control the training details, the authors HIGHLY recommend ``tl.iterate`` see two MNIST examples `1 <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_mlp_dropout1.py>`_, `2 <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_mlp_dropout1.py>`_.
  
      Parameters
      ----------
      network : TensorLayer Model
          the network to be trained.
      train_op : TensorFlow optimizer
          The optimizer for training e.g. tf.optimizers.Adam().
      cost : TensorLayer or TensorFlow loss function
          Metric for loss function, e.g tl.cost.cross_entropy.
      X_train : numpy.array
          The input of training data
      y_train : numpy.array
          The target of training data
      acc : TensorFlow/numpy expression or None
          Metric for accuracy or others. If None, would not print the information.
      batch_size : int
          The batch size for training and evaluating.
      n_epoch : int
          The number of training epochs.
      print_freq : int
          Print the training information every ``print_freq`` epochs.
      X_val : numpy.array or None
          The input of validation data. If None, would not perform validation.
      y_val : numpy.array or None
          The target of validation data. If None, would not perform validation.
      eval_train : boolean
          Whether to evaluate the model during training.
          If X_val and y_val are not None, it reflects whether to evaluate the model on training data.
      tensorboard_dir : string
          path to log dir, if set, summary data will be stored to the tensorboard_dir/ directory for visualization with tensorboard. (default None)
      tensorboard_epoch_freq : int
          How many epochs between storing tensorboard checkpoint for visualization to log/ directory (default 5).
      tensorboard_weight_histograms : boolean
          If True updates tensorboard data in the logs/ directory for visualization
          of the weight histograms every tensorboard_epoch_freq epoch (default True).
      tensorboard_graph_vis : boolean
          If True stores the graph in the tensorboard summaries saved to log/ (default True).
  
      Examples
      --------
      See `tutorial_mnist_simple.py <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_mnist_simple.py>`_
  
      >>> tl.utils.fit(network, train_op=tf.optimizers.Adam(learning_rate=0.0001),
      ...              cost=tl.cost.cross_entropy, X_train=X_train, y_train=y_train, acc=acc,
      ...              batch_size=64, n_epoch=20, _val=X_val, y_val=y_val, eval_train=True)
      >>> tl.utils.fit(network, train_op, cost, X_train, y_train,
      ...            acc=acc, batch_size=500, n_epoch=200, print_freq=5,
      ...            X_val=X_val, y_val=y_val, eval_train=False, tensorboard=True)
  
      Notes
      --------
      'tensorboard_weight_histograms' and 'tensorboard_weight_histograms' are not supported now.
  
      """
      if X_train.shape[0] < batch_size:
          raise AssertionError(
              "Number of training examples should be bigger than the batch size"
          )
  
      if tensorboard_dir is not None:
          tl.logging.info("Setting up tensorboard ...")
          # Set up tensorboard summaries and saver
          tl.files.exists_or_mkdir(tensorboard_dir)
  
          # Only write summaries for more recent TensorFlow versions
          if hasattr(tf, "summary") and hasattr(
              tf.summary, "create_file_writer"
          ):
              train_writer = tf.summary.create_file_writer(
                  tensorboard_dir + "/train"
              )
              val_writer = tf.summary.create_file_writer(
                  tensorboard_dir + "/validation"
              )
              if tensorboard_graph_vis:
                  # FIXME : not sure how to add tl network graph
                  pass
      else:
          train_writer = None
          val_writer = None
  
          tl.logging.info(
              "Finished! use `tensorboard --logdir=%s/` to start tensorboard"
              % tensorboard_dir
          )
  
      tl.logging.info("Start training the network ...")
      start_time_begin = time.time()
      for epoch in range(n_epoch):
          start_time = time.time()
          loss_ep, _, __ = train_epoch(
              network,
              X_train,
              y_train,
              cost=cost,
              train_op=train_op,
              batch_size=batch_size,
          )
  
          train_loss, train_acc = None, None
          val_loss, val_acc = None, None
          if tensorboard_dir is not None and hasattr(tf, "summary"):
              if (
                  epoch + 1 == 1
                  or (epoch + 1) % tensorboard_epoch_freq == 0
              ):
                  if eval_train is True:
                      train_loss, train_acc, _ = run_epoch(
                          network,
                          X_train,
                          y_train,
                          cost=cost,
                          acc=acc,
                          batch_size=batch_size,
                      )
                      with train_writer.as_default():
                          tf.compat.v2.summary.scalar(
                              "loss", train_loss, step=epoch
                          )
                          if acc is not None:
                              tf.summary.scalar(
                                  "acc", train_acc, step=epoch
                              )
                      # FIXME : there seems to be an internal error in Tensorboard (misuse of tf.name_scope)
                      # if tensorboard_weight_histograms is not None:
                      #     for param in network.all_weights:
                      #         tf.summary.histogram(param.name, param, step=epoch)
  
                  if (X_val is not None) and (y_val is not None):
                      val_loss, val_acc, _ = run_epoch(
                          network,
                          X_val,
                          y_val,
                          cost=cost,
                          acc=acc,
                          batch_size=batch_size,
                      )
                      with val_writer.as_default():
                          tf.summary.scalar(
                              "loss", val_loss, step=epoch
                          )
                          if acc is not None:
                              tf.summary.scalar(
                                  "acc", val_acc, step=epoch
                              )
                          # FIXME : there seems to be an internal error in Tensorboard (misuse of tf.name_scope)
                          # if tensorboard_weight_histograms is not None:
                          #     for param in network.all_weights:
                          #         tf.summary.histogram(param.name, param, step=epoch)
  
          if epoch + 1 == 1 or (epoch + 1) % print_freq == 0:
              if (X_val is not None) and (y_val is not None):
                  tl.logging.info(
                      "Epoch %d of %d took %fs"
                      % (epoch + 1, n_epoch, time.time() - start_time)
                  )
                  if eval_train is True:
                      if train_loss is None:
                          train_loss, train_acc, _ = run_epoch(
                              network,
                              X_train,
                              y_train,
                              cost=cost,
                              acc=acc,
                              batch_size=batch_size,
                          )
                      tl.logging.info("   train loss: %f" % train_loss)
                      if acc is not None:
                          tl.logging.info(
                              "   train acc: %f" % train_acc
                          )
                  if val_loss is None:
                      val_loss, val_acc, _ = run_epoch(
                          network,
                          X_val,
                          y_val,
                          cost=cost,
                          acc=acc,
                          batch_size=batch_size,
                      )
  
                  # tl.logging.info("   val loss: %f" % val_loss)
  
                  if acc is not None:
                      pass
                      # tl.logging.info("   val acc: %f" % val_acc)
              else:
                  tl.logging.info(
                      "Epoch %d of %d took %fs, loss %f"
                      % (
                          epoch + 1,
                          n_epoch,
                          time.time() - start_time,
                          loss_ep,
                      )
                  )
      tl.logging.info(
          "Total training time: %fs" % (time.time() - start_time_begin)
      )
  
imports: import os
  import random
  import subprocess
  import sys
  import time
  from collections import Counter
  from sys import exit
  from sys import platform
  import numpy
  import tensorflow
  from sklearn.metrics import accuracy_score, confusion_matrix, f1_score
  import tensorlayer
label_desc: Use image node_id 1 for calling a global function with example usage: fit(network, train_op, cost, X_train, y_train, acc, batch_size, n_epoch, print_freq, X_val, y_val, eval_train, tensorboard_dir, tensorboard_epoch_freq, tensorboard_weight_histograms, tensorboard_graph_vis) without return types