code: def format_output_line(
      img_name, true_class, probs, class_mapping, top_n=3
  ):
      class_probs = np.column_stack((probs, class_mapping)).tolist()
      class_probs.sort(key=lambda x: float(x[0]), reverse=True)
      top_n = (
          min(top_n, len(class_mapping))
          if top_n > 0
          else len(class_mapping)
      )
      true_class_name = (
          class_mapping[true_class] if true_class >= 0 else "unknown"
      )
      line = '[{"class": "%s", "predictions": {' % true_class_name
      for i in range(0, top_n):
          line = '%s"%s":%.3f, ' % (
              line,
              class_probs[i][1],
              float(class_probs[i][0]),
          )
      line = '%s}, "image": "%s"}]\n' % (
          line[:-2],
          img_name.replace("\\", "/").rsplit("/", 1)[1],
      )
      return line
  
file_path: CNTK/Examples/Image/TransferLearning/TransferLearning_Extended.py
imports: from __future__ import print_function
  import numpy
  import os
  from cntk import load_model
  from TransferLearning import *
label_desc: Use image node_id 3 for calling a global function with example usage: format_output_line(img_name, true_class, probs, class_mapping, top_n) and returns: line