| import os |
|
|
| import joblib |
| from keras.models import load_model |
|
|
|
|
| class Model: |
| def __init__(self) -> None: |
| |
| self.__model_lstm = os.path.join("model", "model_health_best.keras") |
| |
| |
| self.__model_binary = os.path.join("model", "model_binary_smote.pkl") |
| self.__model_multiclass = os.path.join("model", "model_multi.pkl") |
| |
| |
| self.__scaler_lstm = os.path.join("model", "scaler_lstm.pkl") |
| |
| |
| 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)}") |
|
|