MCPcopy Create free account
hub / github.com/google-research/language / evaluate_checkpoints

Function evaluate_checkpoints

language/capwap/utils/experiment_utils.py:211–362  ·  view source on GitHub ↗

Continuously loops while checking for checkpoints to evaluate. Args: estimator: Instance of Estimator. caption_input_fn: Estimator input function for supervised captioning. caption_eval_fn: Evaluation callback on captioning output. vqa_input_fn: Estimator input function for visual

(
    estimator,
    caption_input_fn=None,
    caption_eval_fn=None,
    vqa_input_fn=None,
    vqa_eval_fn=None,
    max_checkpoint_number=None,
)

Source from the content-addressed store, hash-verified

209
210
211def evaluate_checkpoints(
212 estimator,
213 caption_input_fn=None,
214 caption_eval_fn=None,
215 vqa_input_fn=None,
216 vqa_eval_fn=None,
217 max_checkpoint_number=None,
218):
219 """Continuously loops while checking for checkpoints to evaluate.
220
221 Args:
222 estimator: Instance of Estimator.
223 caption_input_fn: Estimator input function for supervised captioning.
224 caption_eval_fn: Evaluation callback on captioning output.
225 vqa_input_fn: Estimator input function for visual qa.
226 vqa_eval_fn: Evaluation callback on visual qa output.
227 max_checkpoint_number: Stop after this checkpoint is evaluated.
228 """
229
230 def _compare_metrics(x, y):
231 """Compare metrics of result x to result y."""
232 metric_x = FLAGS.metric_sign * x.get(FLAGS.metric, 0)
233 metric_y = FLAGS.metric_sign * y.get(FLAGS.metric, 0)
234 tf.logging.info("Metric: %s\tNew: %2.4f\tOld: %2.4f", FLAGS.metric,
235 metric_x, metric_y)
236 return metric_x > metric_y
237
238 # Store best
239 best_results = None
240 best_path = os.path.join(estimator.model_dir, "model.ckpt-best")
241
242 # Init async threads.
243 threads = multiprocessing.pool.ThreadPool(2)
244
245 # Reload best from disk.
246 if tf.io.gfile.exists(best_path + ".eval"):
247 with tf.io.gfile.GFile(best_path + ".eval", "r") as f:
248 best_results = json.load(f)
249
250 # Summary writer
251 summaries = tf.summary.FileWriter(os.path.join(estimator.model_dir, "eval"))
252
253 # Track evaluated checkpoints.
254 ckpt_manager = os.path.join(estimator.model_dir, "evaluated_ckpts.json")
255 tf.io.gfile.makedirs(estimator.model_dir)
256 if tf.io.gfile.exists(ckpt_manager):
257 with tf.io.gfile.GFile(ckpt_manager, "r") as f:
258 visited = set(json.load(f))
259 else:
260 visited = set()
261
262 # Iterate over checkpoint files as they appear.
263 for ckpt in checkpoints_iterator(estimator.model_dir):
264 current_step = int(os.path.basename(ckpt).split("-")[1])
265
266 # Skip if already evaluated.
267 if ckpt in visited:
268 continue

Callers

nothing calls this directly

Calls 8

checkpoints_iteratorFunction · 0.85
_compare_metricsFunction · 0.85
splitMethod · 0.80
loadMethod · 0.45
predictMethod · 0.45
getMethod · 0.45
addMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…