code: def get_successful_models(
      num_models, log_file_pattern, difference_threshold=1.0
  ):
      assert num_models > 0
  
      parse_regex = re.compile(
          "LOG .* Overall average objective function for "
          "'output' is ([0-9e.\-+= ]+) over ([0-9e.\-+]+) frames"
      )
      objf = []
      for i in range(num_models):
          model_num = i + 1
          logfile = re.sub("%", str(model_num), log_file_pattern)
          lines = open(logfile, "r").readlines()
          this_objf = -100000.0
          for line_num in range(1, len(lines) + 1):
              # we search from the end as this would result in
              # lesser number of regex searches. Python regex is slow !
              mat_obj = parse_regex.search(lines[-1 * line_num])
              if mat_obj is not None:
                  this_objf = float(mat_obj.groups()[0].split()[-1])
                  break
          objf.append(this_objf)
      max_index = objf.index(max(objf))
      accepted_models = []
      for i in range(num_models):
          if (objf[max_index] - objf[i]) <= difference_threshold:
              accepted_models.append(i + 1)
  
      if len(accepted_models) != num_models:
          logger.warn(
              "Only {0}/{1} of the models have been accepted "
              "for averaging, based on log files {2}.".format(
                  len(accepted_models), num_models, log_file_pattern
              )
          )
  
      return [accepted_models, max_index + 1]
  
imports: from __future__ import division
  import argparse
  import glob
  import logging
  import os
  import math
  import re
  import shutil
  import libs.common
  from libs.nnet3.train.dropout_schedule import *
  import unittest
label_desc: Use image node_id 3 for calling a global function with example usage: get_successful_models(num_models, log_file_pattern, difference_threshold) and returns: list