Skip to content

Commit

Permalink
Further fixing on test files and the files being tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
PRodriguezFlores committed Oct 6, 2023
1 parent 4d71a4d commit fd78505
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
7 changes: 5 additions & 2 deletions resources/src/ai/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
import configparser
from datetime import datetime
from src.ai.outliers import Autoencoder
from tensorflow import keras
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

"""
This module extends the Autoencoder class to allow further training of the model.
"""

class Trainer(Autoencoder):
"""
Class for training the autoencoder model for anomaly detection.
Expand Down Expand Up @@ -138,4 +141,4 @@ def train(self, raw_data, epochs=20, batch_size=32, backup_path=None):
loss = self.model_loss(prep_data, self.model.predict(prep_data), single_value=False).numpy()
self.AVG_LOSS = 0.9*self.AVG_LOSS + 0.1*loss.mean()
self.STD_LOSS = 0.9*self.AVG_LOSS + 0.1*loss.std()
self.save_model(self.model_file ,self.model_config_file)
self.save_model(self.model_file ,self.model_config_file)
14 changes: 7 additions & 7 deletions resources/src/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class Logger:
def __init__(self, log_level=logging.INFO, log_file=None): # Accept log_file as an argument with a default value
if log_file is None:
log_file = './outliers.log'
try:
from config import configmanager
config = configmanager.ConfigManager(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "config.ini"))
log_file = config.get('Logger', 'log_file')
except Exception as e:
print("Could not resolve ConfigManager, default set to ./outliers.log")
try:
from src.config import configmanager
config = configmanager.ConfigManager(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "config.ini"))
log_file = config.get('Logger', 'log_file')
except Exception as e:
print("Could not resolve ConfigManager, default set to ./outliers.log")
self.logger = PyLogrus(name="Outlierslogger")
log_dir = os.path.dirname(log_file)
if not os.path.isdir(log_dir):
Expand Down Expand Up @@ -72,4 +72,4 @@ def debug(self, message):
def error(self, message):
self.logger.error(message)

logger = Logger()
logger = Logger()
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion resources/tests/test_outliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import unittest
import os
import sys
import logging
import json

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
Expand Down
2 changes: 1 addition & 1 deletion resources/tests/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TestTrainer(unittest.TestCase):
def setUp(self):
self.test_backup_path = "./resources/tests/test_backups/"
os.makedirs(self.test_backup_path, exist_ok=True)
self.trainer = Trainer("./resources/tests/test_model.keras", "./resources/tests/test_model_config.ini")
self.trainer = Trainer("./resources/tests/model_test.keras", "./resources/tests/model_test_config.ini")
self.trainer.model_config_file = "./resources/tests/dummy_config.ini"
self.trainer.model_file = "./resources/tests/dummy.keras"

Expand Down

0 comments on commit fd78505

Please sign in to comment.