code: def train_and_eval(
      _base_model_file,
      _train_image_folder,
      _test_image_folder,
      _results_file,
      _new_model_file,
      testing=False,
  ):
      # check for model and data existence
      if not (
          os.path.exists(_base_model_file)
          and os.path.exists(_train_image_folder)
          and os.path.exists(_test_image_folder)
      ):
          print(
              "Please run 'python install_data_and_model.py' first to get the required data and model."
          )
          exit(0)
  
      # get class mapping and map files from train and test image folder
      class_mapping = create_class_mapping_from_folder(
          _train_image_folder
      )
      train_map_file = create_map_file_from_folder(
          _train_image_folder, class_mapping
      )
      test_map_file = create_map_file_from_folder(
          _test_image_folder, class_mapping, include_unknown=True
      )
  
      # train
      trained_model = train_model(
          _base_model_file,
          feature_node_name,
          last_hidden_node_name,
          image_width,
          image_height,
          num_channels,
          len(class_mapping),
          train_map_file,
          num_epochs=30,
          freeze=True,
      )
  
      if not testing:
          trained_model.save(_new_model_file)
          print("Stored trained model at %s" % _new_model_file)
  
      # evaluate test images
      with open(_results_file, "w") as output_file:
          with open(test_map_file, "r") as input_file:
              for line in input_file:
                  tokens = line.rstrip().split("\t")
                  img_file = tokens[0]
                  true_label = int(tokens[1])
                  probs = eval_single_image(
                      trained_model, img_file, image_width, image_height
                  )
  
                  formatted_line = format_output_line(
                      img_file, true_label, probs, class_mapping
                  )
                  output_file.write(formatted_line)
  
      print("Done. Wrote output to %s" % _results_file)
  
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 4 for calling a global function with example usage: train_and_eval(_base_model_file, _train_image_folder, _test_image_folder, _results_file, _new_model_file, testing) without return types