From 5f810275c9584a185a9e96383f8d4abf7907064f Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 24 Jul 2019 08:53:00 -0400 Subject: [PATCH] added min accuracy to models test --- pytorch_lightning/models/trainer.py | 8 ++++++++ tests/test_models.py | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/models/trainer.py b/pytorch_lightning/models/trainer.py index b7f8fbe7..a5c90711 100644 --- a/pytorch_lightning/models/trainer.py +++ b/pytorch_lightning/models/trainer.py @@ -264,6 +264,14 @@ class Trainer(TrainerIO): return tqdm_dic + @property + def tng_tqdm_dic(self): + """ + Read-only for tqdm metrics + :return: + """ + return self.__tng_tqdm_dic + def __layout_bookeeping(self): # training bookeeping self.total_batch_nb = 0 diff --git a/tests/test_models.py b/tests/test_models.py index 36bc87bf..87e9bd31 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -3,10 +3,15 @@ from pytorch_lightning import Trainer from pytorch_lightning.examples.new_project_templates.lightning_module_template import LightningTemplateModel from argparse import Namespace from test_tube import Experiment +import numpy as np import warnings import torch import os +SEED = 2334 +torch.manual_seed(SEED) +np.random.seed(SEED) + def get_model(): root_dir = os.path.dirname(os.path.realpath(__file__)) @@ -26,6 +31,10 @@ def get_exp(): exp = Experiment(debug=True) return exp +def assert_ok_acc(trainer): + # this model should get 0.80+ acc + assert trainer.tng_tqdm_dic['val_acc'] > 0.80 + def test_cpu_model(): model = get_model() @@ -38,10 +47,11 @@ def test_cpu_model(): result = trainer.fit(model) - metrics = result.__tng_tqdm_dic + metrics = trainer.tng_tqdm_dic print(metrics) assert result == 1 + assert_ok_acc(trainer) def test_single_gpu_model(): @@ -66,6 +76,7 @@ def test_single_gpu_model(): result = trainer.fit(model) assert result == 1 + assert_ok_acc(trainer) def test_multi_gpu_model_dp(): @@ -93,6 +104,7 @@ def test_multi_gpu_model_dp(): result = trainer.fit(model) assert result == 1 + assert_ok_acc(trainer) def test_multi_gpu_model_ddp(): @@ -121,6 +133,7 @@ def test_multi_gpu_model_ddp(): result = trainer.fit(model) assert result == 1 + assert_ok_acc(trainer) def test_amp_gpu_ddp(): @@ -150,6 +163,7 @@ def test_amp_gpu_ddp(): result = trainer.fit(model) assert result == 1 + assert_ok_acc(trainer) def test_amp_gpu_dp(): @@ -179,6 +193,7 @@ def test_amp_gpu_dp(): result = trainer.fit(model) assert result == 1 + assert_ok_acc(trainer) if __name__ == '__main__':