wandb 0.20.0__py3-none-any.whl → 0.20.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wandb/__init__.py CHANGED
@@ -10,7 +10,7 @@ For reference documentation, see https://docs.wandb.com/ref/python.
10
10
  """
11
11
  from __future__ import annotations
12
12
 
13
- __version__ = "0.20.0"
13
+ __version__ = "0.20.1"
14
14
 
15
15
 
16
16
  from wandb.errors import Error
wandb/__init__.pyi CHANGED
@@ -106,7 +106,7 @@ if TYPE_CHECKING:
106
106
  import wandb
107
107
  from wandb.plot import CustomChart
108
108
 
109
- __version__: str = "0.20.0"
109
+ __version__: str = "0.20.1"
110
110
 
111
111
  run: Run | None
112
112
  config: wandb_config.Config
@@ -58,25 +58,39 @@ def _warn_on_invalid_data_range(
58
58
  )
59
59
 
60
60
 
61
- def _normalize(data: "np.ndarray") -> "np.ndarray":
62
- """Normalizes and converts image pixel values to uint8 in the range [0, 255]."""
63
- np = util.get_module(
64
- "numpy",
65
- required="wandb.Image requires numpy if not supplying PIL Images: pip install numpy",
66
- )
61
+ def _guess_and_rescale_to_0_255(data: "np.ndarray") -> "np.ndarray":
62
+ """Guess the image's format and rescale its values to the range [0, 255].
63
+
64
+ This is an unfortunate design flaw carried forward for backward
65
+ compatibility. A better design would have been to document the expected
66
+ data format and not mangle the data provided by the user.
67
+
68
+ If given data in the range [0, 1], we multiply all values by 255
69
+ and round down to get integers.
70
+
71
+ If given data in the range [-1, 1], we rescale it by mapping -1 to 0 and
72
+ 1 to 255, then round down to get integers.
73
+
74
+ We clip and round all other data.
75
+ """
76
+ try:
77
+ import numpy as np
78
+ except ImportError:
79
+ raise wandb.Error(
80
+ "wandb.Image requires numpy if not supplying PIL images: pip install numpy"
81
+ ) from None
67
82
 
68
- # if an image has negative values, set all values to be in the range [0, 1]
69
- # This can lead to inconsistent behavior when an image has only a single negative value
70
- if np.min(data) < 0:
71
- data = data - np.min(data)
83
+ data_min: float = data.min()
84
+ data_max: float = data.max()
72
85
 
73
- if np.ptp(data) != 0:
74
- data = data / np.ptp(data)
86
+ if 0 <= data_min and data_max <= 1:
87
+ return (data * 255).astype(np.uint8)
75
88
 
76
- if np.max(data) <= 1.0:
77
- data = (255 * data).astype(np.int32)
89
+ elif -1 <= data_min and data_max <= 1:
90
+ return (255 * 0.5 * (data + 1)).astype(np.uint8)
78
91
 
79
- return data.clip(0, 255)
92
+ else:
93
+ return data.clip(0, 255).astype(np.uint8)
80
94
 
81
95
 
82
96
  def _convert_to_uint8(data: "np.ndarray") -> "np.ndarray":
@@ -393,7 +407,7 @@ class Image(BatchableMedia):
393
407
 
394
408
  _warn_on_invalid_data_range(data, normalize)
395
409
 
396
- data = _normalize(data) if normalize else data # type: ignore [arg-type]
410
+ data = _guess_and_rescale_to_0_255(data) if normalize else data # type: ignore [arg-type]
397
411
  data = _convert_to_uint8(data)
398
412
 
399
413
  if data.ndim > 2:
@@ -413,7 +427,7 @@ class Image(BatchableMedia):
413
427
  _warn_on_invalid_data_range(data, normalize) # type: ignore [arg-type]
414
428
 
415
429
  mode = mode or self.guess_mode(data, file_type)
416
- data = _normalize(data) if normalize else data # type: ignore [arg-type]
430
+ data = _guess_and_rescale_to_0_255(data) if normalize else data # type: ignore [arg-type]
417
431
  data = _convert_to_uint8(data) # type: ignore [arg-type]
418
432
  self._image = pil_image.fromarray(
419
433
  data,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wandb
3
- Version: 0.20.0
3
+ Version: 0.20.1
4
4
  Summary: A CLI and library for interacting with the Weights & Biases API.
5
5
  Project-URL: Source, https://github.com/wandb/wandb
6
6
  Project-URL: Bug Reports, https://github.com/wandb/wandb/issues
@@ -1,6 +1,6 @@
1
1
  package_readme.md,sha256=U9047nyMDICgctm1HLm4HfXwFnFKsEn2m77hsYPUZ1I,4298
2
- wandb/__init__.py,sha256=Q0K6cKpsIpkEcwlfEagt0w2vTeQpORSgjX-51m9GzL4,7072
3
- wandb/__init__.pyi,sha256=kZo96SFeW-OLP6hIGhyi7224rxhs_79UxnRET5v3lk4,48123
2
+ wandb/__init__.py,sha256=voeAUjikukV1wUbzWpSRKezgf6AEE6NODckD2qsuHCU,7072
3
+ wandb/__init__.pyi,sha256=nWUVGrUbymxXWlYwbkoakcN5EbXF-15ZJkXThTGKXTg,48123
4
4
  wandb/__main__.py,sha256=gripuDgB7J8wMMeJt4CIBRjn1BMSFr5zvsrt585Pnj4,64
5
5
  wandb/_iterutils.py,sha256=NX6MaIE3JzPXsqKNXUKdnpIlX0spGG8HwGIQt5VASrk,2400
6
6
  wandb/data_types.py,sha256=M-wqAO0FtIqvj28556u3h4nzSwlRcbxhXoX0B9jlJSo,2283
@@ -325,7 +325,7 @@ wandb/sdk/data_types/bokeh.py,sha256=RuMsi7v_yJyMEuYjfrwTL1q1B8svdCW9t_eNge9aEJA
325
325
  wandb/sdk/data_types/graph.py,sha256=_P_z2dNj2mCJeSvusIfVHkSkVB9AL0AEO-6KaguC1ys,12089
326
326
  wandb/sdk/data_types/histogram.py,sha256=syx3fUDoP6vYqA3r5m7bHXK6MAWo2MkRhpCKasihwvg,3145
327
327
  wandb/sdk/data_types/html.py,sha256=HTh2nNlJsncLgou1gXz6e-f_loaHInMEJerzlDLqKzc,4381
328
- wandb/sdk/data_types/image.py,sha256=Al6Jtgm8_uDcSy9JnQf0L3MSmYb72Ep4u8eKQVxO0Io,34314
328
+ wandb/sdk/data_types/image.py,sha256=xdYth860StgcqoUJ0o4NPncj83XB5BRWI7ypY5PbrUY,34811
329
329
  wandb/sdk/data_types/molecule.py,sha256=_eVzkFEO-uydch8dsw6GjaW_hNGrZwUFfU_inMj70gM,8549
330
330
  wandb/sdk/data_types/object_3d.py,sha256=83ordMmzmmFun2fp2z9P3dffNJ0fW_Hv7MfpDZROYcc,16282
331
331
  wandb/sdk/data_types/plotly.py,sha256=LEIHRqtHHpSou04AEUsyH8_UMXP4adrEHHaKoEtQkxo,2913
@@ -906,8 +906,8 @@ wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/importlib2.py,sha256=cJIaJ2EQso
906
906
  wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/platform.py,sha256=UORYTNVcUSE2NpFcq9UVLIS-tsS0TS_Qw8akhKxn2eY,1506
907
907
  wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/unicode_paths.py,sha256=UWX8DB97ygkEeSxWQUYCHR4MahNilux7vl5TCTQtPPk,2190
908
908
  wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/win32stat.py,sha256=ZOevOTbSo8NRiIxkuBVGaG4yigWnPoO0goxAi-jsBkM,3828
909
- wandb-0.20.0.dist-info/METADATA,sha256=7aUxNBHbW0VdFy4_MAq7vLOn0usyft9ttAQ0J2QWucI,10307
910
- wandb-0.20.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
911
- wandb-0.20.0.dist-info/entry_points.txt,sha256=v4FCOZ9gW7Pc6KLsmgQqpCiKTrA1wh2XHmNf-NUP1-I,67
912
- wandb-0.20.0.dist-info/licenses/LICENSE,sha256=izOKRJpGOx1PrJiGOKR0HsNdlB5JdH2d0Z4P7a7ssTc,1081
913
- wandb-0.20.0.dist-info/RECORD,,
909
+ wandb-0.20.1.dist-info/METADATA,sha256=EcYDqPeeoZYy-r-YORdy-49B7a9AswwzGfIU1lA61-k,10307
910
+ wandb-0.20.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
911
+ wandb-0.20.1.dist-info/entry_points.txt,sha256=v4FCOZ9gW7Pc6KLsmgQqpCiKTrA1wh2XHmNf-NUP1-I,67
912
+ wandb-0.20.1.dist-info/licenses/LICENSE,sha256=izOKRJpGOx1PrJiGOKR0HsNdlB5JdH2d0Z4P7a7ssTc,1081
913
+ wandb-0.20.1.dist-info/RECORD,,
File without changes