added multiple outputs to LightningTestModel

This commit is contained in:
William Falcon
2019-07-24 17:18:58 -04:00
parent 9101a70024
commit 3521e87286
2 changed files with 18 additions and 7 deletions
+1 -1
View File
@@ -225,7 +225,7 @@ class Trainer(TrainerIO):
if self.use_amp:
print('using 16bit precision')
if use_amp and not APEX_AVAILABLE:
if use_amp and not APEX_AVAILABLE: # pragma: no cover
msg = '''
You set use_amp=True but do not have apex installed.
Install apex first using this guide and rerun with use_amp=True:
@@ -126,13 +126,23 @@ class LightningTestModel(LightningModule):
loss_val = loss_val.unsqueeze(0)
val_acc = val_acc.unsqueeze(0)
output = OrderedDict({
'val_loss': loss_val,
'val_acc': val_acc,
})
# alternate possible outputs to test
if self.trainer.batch_nb % 0 == 0:
output = OrderedDict({
'val_loss': loss_val,
'val_acc': val_acc,
})
return output
if self.trainer.batch_nb % 1 == 0:
return val_acc
# can also return just a scalar instead of a dict (return loss_val)
return output
if self.trainer.batch_nb % 2 == 0:
output = OrderedDict({
'val_loss': loss_val,
'val_acc': val_acc,
'test_dic': {'val_loss_a': loss_val}
})
return output
def validation_end(self, outputs):
"""
@@ -152,6 +162,7 @@ class LightningTestModel(LightningModule):
val_loss_mean /= len(outputs)
val_acc_mean /= len(outputs)
tqdm_dic = {'val_loss': val_loss_mean.item(), 'val_acc': val_acc_mean.item()}
return tqdm_dic