save ocsvm and isoforest models during training

This commit is contained in:
Jan Kowalczyk
2025-06-20 09:16:08 +02:00
parent bbd093da0c
commit c552173cb2
3 changed files with 27 additions and 132 deletions

View File

@@ -287,11 +287,13 @@ class IsoForest(object):
def save_model(self, export_path):
"""Save Isolation Forest model to export_path."""
pass
with open(export_path, "wb") as fp:
pickle.dump(self.model, fp)
def load_model(self, import_path, device: str = "cpu"):
"""Load Isolation Forest model from import_path."""
pass
with open(import_path, "rb") as fp:
self.model = pickle.load(fp)
def save_results(self, export_pkl):
"""Save results dict to a JSON-file."""

View File

@@ -1,6 +1,7 @@
import logging
import pickle
import time
from pathlib import Path
import numpy as np
import torch
@@ -478,12 +479,13 @@ class OCSVM(object):
self.ae_net.to(torch.device(device))
self.ae_net.eval()
def save_model(self, export_path):
def save_model(self, export_path: Path):
"""Save OC-SVM model to export_path."""
pass
self.model.save_to_file(export_path)
def load_model(self, import_path, device: str = "cpu"):
def load_model(self, import_path: Path):
"""Load OC-SVM model from import_path."""
self.model.save_to_file(import_path)
pass
def save_results(self, export_pkl):