Przeglądaj źródła

added evaluation method to the default finetuner

Dimitri Korsch 3 lat temu
rodzic
commit
f1b8628c57
1 zmienionych plików z 18 dodań i 0 usunięć
  1. 18 0
      cvfinetune/finetuner/mixins/trainer.py

+ 18 - 0
cvfinetune/finetuner/mixins/trainer.py

@@ -146,6 +146,24 @@ class _TrainerMixin(BaseMixin):
         else:
             self.dump("final")
 
+    def evaluate(self,
+        eval_fpath: T.Optional[T.Union[Path, str]] = None,
+        *,
+        force: bool = False):
+
+        eval_fpath = Path(eval_fpath)
+
+        if eval_fpath.exists() and not force:
+            logging.warning(f"Evaluation file (\"{eval_fpath}\") exists already, skipping evaluation")
+            return
+
+        records = self.evaluator()
+
+        records = {key: float(value) for key, value in records.items()}
+        with open(eval_fpath, "w") as f:
+            pyaml.dump(records, f, sort_keys=False)
+
+
 
     def run_experiment(self, *args, **kwargs):