Skip to content

Conversation

@Marius-Graml
Copy link

Description

Image artifactsaver class added. Images can be saved in ".png", ".jpg", ".jpeg", and "webp". Images are automatically saved to a local directory named "canonical". Supported model outputs are "torch.Tensor", "numpy.ndarray" and "PIL.Image".

Related Issue

No issues were fixed.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Logged images, which has been saved by the artifactsaver, to wandb.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

/

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment @cursor review or bugbot run to trigger another review on this PR

# Usually, the data is already a PIL.Image, so we don't need to convert it.
if isinstance(data, torch.Tensor):
data = np.transpose(data.cpu().numpy(), (1, 2, 0))
data = np.clip(data * 255, 0, 255).astype(np.uint8)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Uint8 torch tensors incorrectly multiplied by 255

The torch tensor conversion unconditionally multiplies values by 255, assuming float data normalized to [0, 1]. When a uint8 tensor with values in [0, 255] is passed, multiplying by 255 produces values up to 65025, which after clipping means any pixel value ≥2 becomes 255. This corrupts the image, making it nearly all white/saturated. The code needs to check the tensor's dtype before scaling.

Fix in Cursor Fix in Web

data = np.transpose(data.cpu().numpy(), (1, 2, 0))
data = np.clip(data * 255, 0, 255).astype(np.uint8)
if isinstance(data, np.ndarray):
data = Image.fromarray(data.astype(np.uint8))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Float numpy arrays not scaled before uint8 conversion

When a numpy.ndarray with float dtype (values in [0.0, 1.0]) is passed, it's directly cast to uint8 without first multiplying by 255. All float values less than 1.0 truncate to 0, resulting in an all-black image. Unlike the torch tensor path, there's no scaling applied here before the conversion to uint8.

Fix in Cursor Fix in Web

@github-actions
Copy link

This PR has been inactive for 10 days and is now marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants