TensorboardLogger not displaying metrics for LogisticRegression #12762
-
I am currently building a big dataset and infrastructure using PyTorch Lightning. Unfortunately there is no precise information in the documentation. My code can be seen as: datamodule = DataModule(
transform=economy_average_vs_outcome,
download=False,
batch_size=2,
num_workers=4,
)
# Preparing the data:
datamodule.prepare_data()
datamodule.setup()
logistic_regression = LogisticRegression(input_dim=2 * 39, num_classes=2)
logger = TensorBoardLogger("tb_logs", name="Logistic Regression")
trainer = pl.Trainer(
logger=logger,
accelerator="gpu",
devices=1,
auto_select_gpus=True,
max_epochs=50,
log_every_n_steps=2,
)
# Training the model:
trainer.fit(model=logistic_regression, datamodule=datamodule) Keep in mind that this is sample code that is not final. The code for
I should not be required to read the source code for the The def training_step(self, batch: Tuple[Tensor, Tensor], batch_idx: int) -> Dict[str, Tensor]:
x, y = batch
# flatten any input
x = x.view(x.size(0), -1)
y_hat = self.linear(x)
# PyTorch cross_entropy function combines log_softmax and nll_loss in single function
loss = F.cross_entropy(y_hat, y, reduction="sum")
# L1 regularizer
if self.hparams.l1_strength > 0:
l1_reg = self.linear.weight.abs().sum()
loss += self.hparams.l1_strength * l1_reg
# L2 regularizer
if self.hparams.l2_strength > 0:
l2_reg = self.linear.weight.pow(2).sum()
loss += self.hparams.l2_strength * l2_reg
loss /= x.size(0)
tensorboard_logs = {"train_ce_loss": loss}
progress_bar_metrics = tensorboard_logs
return {"loss": loss, "log": tensorboard_logs, "progress_bar": progress_bar_metrics} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
the code in bolts is outdated and logging doesn't work like that anymore. def training_step(self, batch, batch_idx):
...
self.log("train_ce_loss", loss, prog_bar=True) more info herE: https://pytorch-lightning.readthedocs.io/en/stable/extensions/logging.html#logging-from-a-lightningmodule |
Beta Was this translation helpful? Give feedback.
the code in bolts is outdated and logging doesn't work like that anymore.
you need to do:
more info herE: https://pytorch-lightning.readthedocs.io/en/stable/extensions/logging.html#logging-from-a-lightningmodule