Reputation: 115
I'm using Pytorch Lighting and Tensorboard as PyTorch Forecasting library is build using them. I want to create my own loss curves via matplotlib and don't want to use Tensorboard.
It is possible to access metrics at each epoch via a method? Validation Loss, Training Loss etc?
My code is below:
logger = TensorBoardLogger("logs", name = "model")
trainer = pl.Trainer(#Some params)
Does logger or trainer have any method to access this information?
PL documentation isn't clear and there are many methods associated with logger and trainer.
Upvotes: 2
Views: 1420
Reputation: 3476
My recommendation is that you:
from pytorch_lightning.loggers import CSVLogger
csv_logger = CSVLogger(
save_dir='./',
name='csv_file'
)
# Initialize a trainer
trainer = Trainer(
accelerator="auto",
max_epochs=1,
log_every_n_steps=10,
logger=[csv_logger],
)
class MNISTModel(LightningModule):
def __init__(self):
super().__init__()
self.l1 = torch.nn.Linear(28 * 28, 10)
def forward(self, x):
return torch.relu(self.l1(x.view(x.size(0), -1)))
def training_step(self, batch, batch_nb):
x, y = batch
loss = F.cross_entropy(self(x), y)
self.log('loss_epoch', loss, on_step=False, on_epoch=True)
return loss
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=0.02)
Upvotes: 5