-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b06c208
commit 80ff952
Showing
3 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/integration/models/torch/lighting_modules/test_anomaly_detection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from omegaconf import DictConfig | ||
|
||
from innofw.constants import Frameworks, Stages | ||
from innofw.core.datamodules.lightning_datamodules.anomaly_detection_timeseries_dm import \ | ||
TimeSeriesLightningDataModule | ||
from innofw.core.models.torch.lightning_modules import ( | ||
AnomalyDetectionTimeSeriesLightningModule | ||
) | ||
from innofw.utils.framework import get_datamodule | ||
from tests.fixtures.config.datasets import anomaly_detection_timeseries_datamodule_cfg_w_target | ||
from innofw.utils.framework import get_losses | ||
from innofw.utils.framework import get_model | ||
from tests.fixtures.config import losses as fixt_losses | ||
from tests.fixtures.config import models as fixt_models | ||
from tests.fixtures.config import optimizers as fixt_optimizers | ||
from tests.fixtures.config import trainers as fixt_trainers | ||
|
||
|
||
def test_anomaly_detection(): | ||
cfg = DictConfig( | ||
{ | ||
"models": fixt_models.lstm_autoencoder_w_target, | ||
"trainer": fixt_trainers.trainer_cfg_w_cpu_devices, | ||
"losses": fixt_losses.l1_loss_w_target, | ||
} | ||
) | ||
model = get_model(cfg.models, cfg.trainer) | ||
losses = get_losses(cfg, "anomaly-detection-timeseries", Frameworks.torch) | ||
optimizer_cfg = DictConfig(fixt_optimizers.adam_optim_w_target) | ||
|
||
module = AnomalyDetectionTimeSeriesLightningModule( | ||
model=model, losses=losses, optimizer_cfg=optimizer_cfg | ||
) | ||
|
||
assert module is not None | ||
|
||
datamodule: TimeSeriesLightningDataModule = get_datamodule( | ||
anomaly_detection_timeseries_datamodule_cfg_w_target, | ||
Frameworks.torch, | ||
task="anomaly-detection-timeseries" | ||
) | ||
datamodule.setup(Stages.train) | ||
|
||
for stage in ["train", "val"]: | ||
module.stage_step(stage, next(iter(datamodule.train_dataloader())), | ||
do_logging=True) |