code: def find_set_of_labels(image_list, field, output_key):
      label_set = set()
      if field in image_list[0]:
          for idx, image in enumerate(image_list):
              assert field in image, (
                  "label normalisation layer requires {} input, "
                  "however it is not provided in the config file.\n"
                  "Please consider setting "
                  "label_normalisation to False.".format(field)
              )
              print_progress_bar(
                  idx,
                  len(image_list),
                  prefix="searching unique labels from files",
                  decimals=1,
                  length=10,
                  fill="*",
              )
              unique_label = np.unique(image[field].get_data())
              if len(unique_label) > 500 or len(unique_label) <= 1:
                  tf.logging.warning(
                      "unusual discrete values: number of unique "
                      "labels to normalise %s",
                      len(unique_label),
                  )
              label_set.update(set(unique_label))
          label_set = list(label_set)
          label_set.sort()
      try:
          mapping_from_to = dict()
          mapping_from_to[output_key[0]] = tuple(label_set)
          mapping_from_to[output_key[1]] = tuple(
              range(0, len(label_set))
          )
      except (IndexError, ValueError):
          tf.logging.fatal(
              "unable to create mappings keys: %s, image name %s",
              output_key,
              field,
          )
          raise
      return mapping_from_to
  
file_path: NiftyNet/niftynet/layer/discrete_label_normalisation.py
imports: from __future__ import absolute_import, print_function, division
  import os
  import numpy
  import tensorflow
  import niftynet.utilities.histogram_standardisation
  from niftynet.layer.base_layer import DataDependentLayer
  from niftynet.layer.base_layer import Invertible
  from niftynet.utilities.user_parameters_helper import standardise_string
  from niftynet.utilities.util_common import print_progress_bar
label_desc: Use image node_id 1 for calling a global function with example usage: find_set_of_labels(image_list, field, output_key) and returns: mapping_from_to