code: def test(network, acc, X_test, y_test, batch_size, cost=None):
      """
      Test a given non time-series network by the given test data and metric.
  
      Parameters
      ----------
      network : TensorLayer Model
          The network.
      acc : TensorFlow/numpy expression or None
          Metric for accuracy or others.
              - If None, would not print the information.
      X_test : numpy.array
          The input of testing data.
      y_test : numpy array
          The target of testing data
      batch_size : int or None
          The batch size for testing, when dataset is large, we should use minibatche for testing;
          if dataset is small, we can set it to None.
      cost : TensorLayer or TensorFlow loss function
          Metric for loss function, e.g tl.cost.cross_entropy. If None, would not print the information.
  
      Examples
      --------
      See `tutorial_mnist_simple.py <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_mnist_simple.py>`_
  
      >>> def acc(_logits, y_batch):
      ...     return np.mean(np.equal(np.argmax(_logits, 1), y_batch))
      >>> tl.utils.test(network, acc, X_test, y_test, batch_size=None, cost=tl.cost.cross_entropy)
  
      """
      tl.logging.info("Start testing the network ...")
      network.eval()
      if batch_size is None:
          y_pred = network(X_test)
          if cost is not None:
              test_loss = cost(y_pred, y_test)
              # tl.logging.info("   test loss: %f" % test_loss)
          test_acc = acc(y_pred, y_test)
          # tl.logging.info("   test acc: %f" % (test_acc / test_acc))
          return test_acc
      else:
          test_loss, test_acc, n_batch = run_epoch(
              network,
              X_test,
              y_test,
              cost=cost,
              acc=acc,
              batch_size=batch_size,
              shuffle=False,
          )
          if cost is not None:
              tl.logging.info("   test loss: %f" % test_loss)
          tl.logging.info("   test acc: %f" % test_acc)
          return test_acc
  
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 2 for calling a global function with example usage: test(network, acc, X_test, y_test, batch_size, cost) and returns: test_acc, test_acc