Skip to content
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2a5ffb5
docs(sdk): improve image normalization documentation
mdlinville Aug 22, 2025
f62e865
fix: address code formatting issues in image.py docstrings
mdlinville Aug 22, 2025
3e2fb86
docs(sdk): simplify image normalization docstrings - remove detailed …
mdlinville Aug 25, 2025
5b3431f
fix: address code formatting issues in image.py docstrings
mdlinville Aug 25, 2025
fd0b4e1
feat: add image normalization demo notebook for testing and user exam…
mdlinville Aug 25, 2025
f65e93b
docs: add concise normalization example to Image.__init__ docstring
mdlinville Aug 25, 2025
94b946d
docs: add detailed explanations to notebook examples for better under…
mdlinville Aug 25, 2025
ccb43f1
docs: add detailed explanations about contrast effects and when to us…
mdlinville Aug 25, 2025
d5dd9b9
docs: add detailed explanations to all notebook examples including vi…
mdlinville Aug 25, 2025
bde72fa
docs: use --quiet --upgrade flags for pip install to reduce output noise
mdlinville Aug 25, 2025
99b399a
docs: add reassuring note about import cell success
mdlinville Aug 25, 2025
db648dc
docs: add explanation about expected deprecation warning in Example 2
mdlinville Aug 25, 2025
adc9ca9
docs: add reassuring note about import cell success
mdlinville Aug 25, 2025
5051174
docs: restore --quiet --upgrade flags to pip install command
mdlinville Aug 25, 2025
37207c6
docs: remove --upgrade flag from pip install to avoid dependency conf…
mdlinville Aug 25, 2025
615a78c
docs: remove notebook (moved to examples repo PR #609)
mdlinville Aug 25, 2025
b7e30ff
docs: address reviewer feedback on normalization examples and docstri…
mdlinville Aug 25, 2025
10dd4b7
fix: correct docstring formatting for pre-commit hooks
mdlinville Aug 25, 2025
4d7290b
Merge branch 'main' into docs/DOCS-1016-image-normalization-docs
mdlinville Aug 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions wandb/sdk/data_types/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,11 @@ def _warn_on_invalid_data_range(


def _guess_and_rescale_to_0_255(data: "np.ndarray") -> "np.ndarray":
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function is private and shouldn't appear in our documentation; why update its docstring here? I prefer the original for conciseness and developer context. The new version is too verbose and adds irrelevant context about PyTorch, PIL and the normalize parameter to the wandb.Image constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm a little confused about this feedback:

  1. I am not sure why the _guess_and_rescale_to_0_255 function is showing up. @ngrayluna can you take a look? Is there some magic that prevents things starting with an underscore from showing up? Though, I think that this function doesn't show up in the docs, so maybe this is fine. https://docs.wandb.ai/ref/python/sdk/data-types/image/ is the currently published reference, without the changes in this PR.
  2. Preferring more verbose: Is this about lines 66-72 vs lines 60-64 ? Would you like me to revert the change here?

"""Guess the image's format and rescale its values to the range [0, 255].
"""Rescale image data to [0, 255] range based on detected format.

This is an unfortunate design flaw carried forward for backward
compatibility. A better design would have been to document the expected
data format and not mangle the data provided by the user.

If given data in the range [0, 1], we multiply all values by 255
and round down to get integers.

If given data in the range [-1, 1], we rescale it by mapping -1 to 0 and
1 to 255, then round down to get integers.

We clip and round all other data.
If data is in [0, 1] range, multiply by 255.
If data is in [-1, 1] range, rescale to [0, 255].
Otherwise, clip to [0, 255].
"""
try:
import numpy as np
Expand Down Expand Up @@ -169,8 +161,10 @@ def __init__(
If the values are not in the range [0, 255] or all values are in the range [0, 1],
the image pixel values will be normalized to the range [0, 255]
unless `normalize` is set to False.
Comment on lines 161 to 163
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this still be here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you are specifically referring to. It looks to me like this is missing the -1-1 range case. Do you mean that since we have lines 62-64, the detail in 161-3 should be removed?

- pytorch tensor should be in the format (channel, height, width)
- NumPy array should be in the format (height, width, channel)

**Data format requirements:**
- PyTorch tensor should be in the format (channel, height, width)
- NumPy array should be in the format (height, width, channel)
mode: The PIL mode for an image. Most common are "L", "RGB",
"RGBA". Full explanation at https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes
caption: Label for display of image.
Expand Down Expand Up @@ -237,6 +231,24 @@ def __init__(
examples.append(image)
run.log({"examples": examples})
```

Normalization example
```python
import torch
import wandb

# Values in [0, 1] range will be multiplied by 255
tensor_0_1 = torch.rand(3, 64, 64) # Values in [0, 1]
image = wandb.Image(tensor_0_1, caption="Normalized from [0,1] range")

# Values in [-1, 1] range will be rescaled to [0, 255]
tensor_neg1_1 = torch.rand(3, 64, 64) * 2 - 1 # Values in [-1, 1]
image = wandb.Image(tensor_neg1_1, caption="Normalized from [-1,1] range")

# Disable normalization
image = wandb.Image(tensor_0_1, normalize=False, caption="No normalization")
```

"""
super().__init__(caption=caption)
# TODO: We should remove grouping, it's a terrible name and I don't
Expand Down