Validation loss Tensor object is print in progress bar, it is expected only value #4020
Closed
Description
🐛 Bug
When I add validation loss in progress bar training, tensor object is printed whereas only loss value is expected.
For example :
Epoch 1: 100%|██████████| 5/5 [00:04<00:00, 1.21it/s, loss=82.423, v_num=52, val_loss=tensor(76.4331, dtype=torch.float32)]
Validation loss is added with the following command : self.log('val_loss', loss, prog_bar=True)
I tried self.log('val_loss', loss.item(), prog_bar=True) with no effect.
To Reproduce
The bug is reproductible with the minimal code example (https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pl_examples/bug_report_model.py). See code sample below with validation_step overridden :
Code sample
class TestModel(BoringModel):
def validation_step(self, batch, batch_idx):
output = self.layer(batch)
loss = self.loss(batch, output)
self.log('val_loss', loss, prog_bar=True)
return {"x": loss}
Expected behavior
It is expected to only obtain value of validation loss in progress bar and not tensor object.
Environment
- CUDA:
- GPU:
- available: False
- version: None
- Packages:
- numpy: 1.19.1
- pyTorch_debug: False
- pyTorch_version: 1.6.0
- pytorch-lightning: 0.10.0
- tqdm: 4.50.1
- System:
- OS: Darwin
- architecture:
- 64bit
- processor: i386
- python: 3.8.6
- version: Darwin Kernel Version 18.7.0: Thu Jun 18 20:50:10 PDT 2020; root:xnu-4903.278.43~1/RELEASE_X86_64