-
Notifications
You must be signed in to change notification settings - Fork 75
feat: Image artifactsaver #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
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.
…nch as image_artifactsaver depends on these files
|
This PR has been inactive for 10 days and is now marked as stale. |
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
How Has This Been Tested?
Logged images, which has been saved by the artifactsaver, to wandb.
Checklist
Additional Notes
/