diff --git a/python/paddle/hapi/model.py b/python/paddle/hapi/model.py index a1fe1f58643326c5eea2552f3835724610b7378f..1ac873ce9ca509bff1500b9913a28bc5ac0678a6 100644 --- a/python/paddle/hapi/model.py +++ b/python/paddle/hapi/model.py @@ -1707,7 +1707,8 @@ class Model(object): steps = self._len_data_loader(train_loader) self.num_iters = num_iters - if num_iters is not None and isinstance(num_iters, int): + if num_iters is not None and isinstance(num_iters, int) and isinstance( + steps, int): assert num_iters > 0, "num_iters must be greater than 0!" epochs = (num_iters // steps) + 1 steps = min(num_iters, steps) @@ -1742,8 +1743,8 @@ class Model(object): eval_logs = self._run_one_epoch(eval_loader, cbks, 'eval') cbks.on_end('eval', eval_logs) - if self.stop_training: - break + if self.stop_training: + break cbks.on_end('train', logs) self._test_dataloader = None @@ -1830,7 +1831,8 @@ class Model(object): eval_steps = self._len_data_loader(eval_loader) self.num_iters = num_iters - if num_iters is not None and isinstance(num_iters, int): + if num_iters is not None and isinstance(num_iters, int) and isinstance( + eval_steps, int): assert num_iters > 0, "num_iters must be greater than 0!" eval_steps = min(num_iters, eval_steps) self.num_iters = eval_steps @@ -2092,7 +2094,9 @@ class Model(object): callbacks.on_batch_end(mode, step, logs) if hasattr(self, 'num_iters') and self.num_iters is not None: self.num_iters -= 1 - if self.num_iters == 0: + if self.num_iters <= 0: + self.stop_training = True + del self.num_iters break self._reset_metrics()