mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-11 12:31:23 +08:00
added min accuracy to models test
This commit is contained in:
@@ -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
|
||||
|
||||
+16
-1
@@ -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__':
|
||||
|
||||
Reference in New Issue
Block a user