File size: 2,258 Bytes
99ee88a cea3342 13ba4b4 cea3342 13ba4b4 cea3342 99ee88a cea3342 99ee88a 13ba4b4 99ee88a 13ba4b4 99ee88a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import os
import joblib
from keras.models import load_model
class Model:
def __init__(self) -> None:
# Time-Series
self.__model_lstm = os.path.join("model", "model_health_best.keras")
# Anomaly Detection
self.__model_binary = os.path.join("model", "model_binary_smote.pkl")
self.__model_multiclass = os.path.join("model", "model_multi.pkl")
# Scaler Time-Series
self.__scaler_lstm = os.path.join("model", "scaler_lstm.pkl")
# Scaler Anomaly
self.__preprocessor_anomaly = os.path.join("model", "scaler_anomaly.pkl")
self._load_model_and_scalers()
def _load_model_and_scalers(self):
try:
if os.path.exists(self.__model_lstm):
self.model_lstm = load_model(self.__model_lstm)
print("LSTM model loaded successfully")
else:
print(f"⚠ Model not found at {self.__model_lstm}")
if os.path.exists(self.__model_binary):
self.model_binary = joblib.load(self.__model_binary)
print("Binary model loaded successfully")
else:
print(f"⚠ Model not found at {self.__model_binary}")
if os.path.exists(self.__model_multiclass):
self.model_multiclass = joblib.load(self.__model_multiclass)
print("Multiclass model loaded successfully")
else:
print(f"⚠ Model not found at {self.__model_multiclass}")
if os.path.exists(self.__preprocessor_anomaly):
self.preprocessor_anomaly = joblib.load(self.__preprocessor_anomaly)
print("Scaler anomaly model loaded successfully")
else:
print(f"⚠ preprocessor_anomaly not found at {self.__preprocessor_anomaly}")
if os.path.exists(self.__scaler_lstm):
self.scaler_lstm = joblib.load(self.__scaler_lstm)
print("scaler_y loaded successfully")
else:
print(f"⚠ scaler_y not found at {self.__scaler_lstm}")
except Exception as e:
print(f"✗ Error loading model/scalers: {str(e)}")
|