Browse Source

add self.use_ema judgement in base.py

FlyingQianMM 5 years ago
parent
commit
4a7cb725b2
1 changed files with 2 additions and 2 deletions
  1. 2 2
      paddlex/cv/models/base.py

+ 2 - 2
paddlex/cv/models/base.py

@@ -548,7 +548,7 @@ class BaseAPI:
                 current_save_dir = osp.join(save_dir, "epoch_{}".format(i + 1))
                 if not osp.isdir(current_save_dir):
                     os.makedirs(current_save_dir)
-                if self.use_ema:
+                if hasattr(self, 'use_ema') and self.use_ema:
                     self.exe.run(self.ema.apply_program)
                 if eval_dataset is not None and eval_dataset.num_samples > 0:
                     self.eval_metrics, self.eval_details = self.evaluate(
@@ -576,7 +576,7 @@ class BaseAPI:
                             log_writer.add_scalar(
                                 "Metrics/Eval(Epoch): {}".format(k), v, i + 1)
                 self.save_model(save_dir=current_save_dir)
-                if self.use_ema:
+                if hasattr(self, 'use_ema') and self.use_ema:
                     self.exe.run(self.ema.restore_program)
                 time_eval_one_epoch = time.time() - eval_epoch_start_time
                 eval_epoch_start_time = time.time()