MCPcopy Index your code
hub / github.com/tensorflow/models / run

Method run

official/core/train_lib.py:253–304  ·  view source on GitHub ↗

Run experiments by mode. Returns: A 2-tuple of (model, eval_logs). model: `tf_keras.Model` instance. eval_logs: returns eval metrics logs when run_post_eval is set to True, otherwise, returns {}.

(self)

Source from the content-addressed store, hash-verified

251 return controller
252
253 def run(self) -> Tuple[tf_keras.Model, Mapping[str, Any]]:
254 """Run experiments by mode.
255
256 Returns:
257 A 2-tuple of (model, eval_logs).
258 model: `tf_keras.Model` instance.
259 eval_logs: returns eval metrics logs when run_post_eval is set to True,
260 otherwise, returns {}.
261 """
262 mode = self._mode
263 params = self.params
264 logging.info('Starts to execute mode: %s', mode)
265 with self.strategy.scope():
266 if mode == 'train' or mode == 'train_and_post_eval':
267 self.controller.train(steps=params.trainer.train_steps)
268 elif mode == 'train_and_eval':
269 self.controller.train_and_evaluate(
270 train_steps=params.trainer.train_steps,
271 eval_steps=params.trainer.validation_steps,
272 eval_interval=params.trainer.validation_interval)
273 elif mode == 'eval':
274 self.controller.evaluate(steps=params.trainer.validation_steps)
275 elif mode == 'continuous_eval':
276
277 def timeout_fn():
278 if self.trainer.global_step.numpy() >= params.trainer.train_steps:
279 return True
280 return False
281
282 self.controller.evaluate_continuously(
283 steps=params.trainer.validation_steps,
284 timeout=params.trainer.continuous_eval_timeout,
285 timeout_fn=timeout_fn)
286 else:
287 raise NotImplementedError('The mode is not implemented: %s' % mode)
288
289 num_params = train_utils.try_count_params(self.trainer.model)
290 if num_params is not None:
291 logging.info('Number of trainable params in model: %f Millions.',
292 num_params / 10.**6)
293
294 flops = train_utils.try_count_flops(self.trainer.model)
295 if flops is not None:
296 logging.info('FLOPs (multi-adds) in model: %f Billions.',
297 flops / 10.**9 / 2)
298
299 if self._run_post_eval or mode == 'train_and_post_eval':
300 with self.strategy.scope():
301 return self.trainer.model, self.controller.evaluate( # pytype: disable=bad-return-type # always-use-property-annotation
302 steps=params.trainer.validation_steps)
303 else:
304 return self.trainer.model, {}
305
306
307def run_experiment(

Callers 15

run_experimentFunction · 0.95
forwardMethod · 0.45
train_stepMethod · 0.45
train_stepMethod · 0.45
eval_step_fnMethod · 0.45
swap_weightsMethod · 0.45
train.pyFile · 0.45

Calls 5

infoMethod · 0.80
evaluate_continuouslyMethod · 0.80
trainMethod · 0.45
train_and_evaluateMethod · 0.45
evaluateMethod · 0.45

Tested by 15

forwardMethod · 0.36
test_stepFunction · 0.36
test_stepFunction · 0.36
test_stepMethod · 0.36
test_stepMethod · 0.36
test_end_to_end_classMethod · 0.36