Skip to content

Commit 88830aa

Browse files
NathanGodeypre-commit-ci[bot]rohitgr7carmocca
authored andcommitted
WandbLogger's log_image can use step argument (#11716)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Rohit Gupta <[email protected]> Co-authored-by: Carlos Mocholí <[email protected]>
1 parent 6becc4a commit 88830aa

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1111
- Fixed the format of the configuration saved automatically by the CLI's `SaveConfigCallback` ([#11532](https://github.com/PyTorchLightning/pytorch-lightning/pull/11532))
1212
- Fixed an issue to avoid validation loop run on restart ([#11552](https://github.com/PyTorchLightning/pytorch-lightning/pull/11552))
1313
- The Rich progress bar now correctly shows the `on_epoch` logged values on train epoch end ([#11689](https://github.com/PyTorchLightning/pytorch-lightning/pull/11689))
14+
- Fixed an issue to make the `step` argument in `WandbLogger.log_image` work ([#11716](https://github.com/PyTorchLightning/pytorch-lightning/pull/11716))
1415

1516

1617
## [1.5.9] - 2022-01-18

pytorch_lightning/loggers/wandb.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def log_text(
405405
self.log_table(key, columns, data, dataframe, step)
406406

407407
@rank_zero_only
408-
def log_image(self, key: str, images: List[Any], **kwargs: str) -> None:
408+
def log_image(self, key: str, images: List[Any], step: Optional[int] = None, **kwargs: str) -> None:
409409
"""Log images (tensors, numpy arrays, PIL Images or file paths).
410410
411411
Optional kwargs are lists passed to each image (ex: caption, masks, boxes).
@@ -416,7 +416,6 @@ def log_image(self, key: str, images: List[Any], **kwargs: str) -> None:
416416
for k, v in kwargs.items():
417417
if len(v) != n:
418418
raise ValueError(f"Expected {n} items but only found {len(v)} for {k}")
419-
step = kwargs.pop("step", None)
420419
kwarg_list = [{k: kwargs[k][i] for k in kwargs.keys()} for i in range(n)]
421420
metrics = {key: [wandb.Image(img, **kwarg) for img, kwarg in zip(images, kwarg_list)]}
422421
self.log_metrics(metrics, step)

tests/loggers/test_wandb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ def test_wandb_log_media(wandb, tmpdir):
252252
wandb.Image.assert_called_with("2.jpg")
253253
wandb.init().log.assert_called_once_with({"samples": [wandb.Image(), wandb.Image()]})
254254

255+
# test log_image with step
256+
wandb.init().log.reset_mock()
257+
logger.log_image(key="samples", images=["1.jpg", "2.jpg"], step=5)
258+
wandb.Image.assert_called_with("2.jpg")
259+
wandb.init().log.assert_called_once_with({"samples": [wandb.Image(), wandb.Image()], "trainer/global_step": 5})
260+
255261
# test log_image with captions
256262
wandb.init().log.reset_mock()
257263
wandb.Image.reset_mock()

0 commit comments

Comments
 (0)