Closed MalteEbner closed 4 days ago
It looks like torchvision 0.19 will be compatible with numpy 2.0 (source: https://github.com/pytorch/vision/issues/8460#issuecomment-2145217340). Let's require numpy 1.x for now.
Why can't we support both numpy 1 and 2 as soon as possible? Why do we need to wait for other dependencies? Seems like it's a simple fix.
Hey @adamjstewart, thanks for the feedback. We can already migrate the library to NumPy 2.0 as in #1561 but the problem of broken upstream libraries remains. In particular, torchvision 0.18.0 is only 98% compatible (see the tracker issue https://github.com/numpy/numpy/issues/26191) and it appears that we are affected by the remaining two percent: Applying color jitter results in the following error (failing GitHub action):
transformed: Tensor = self.transform(image)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torchvision/transforms/transforms.py:95: in __call__
img = t(img)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torch/nn/modules/module.py:1532: in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torch/nn/modules/module.py:1541: in _call_impl
return forward_call(*args, **kwargs)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torchvision/transforms/transforms.py:540: in forward
img = t(img)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torch/nn/modules/module.py:1532: in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torch/nn/modules/module.py:1541: in _call_impl
return forward_call(*args, **kwargs)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torchvision/transforms/transforms.py:1280: in forward
img = F.adjust_hue(img, hue_factor)
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torchvision/transforms/functional.py:959: in adjust_hue
return F_pil.adjust_hue(img, hue_factor)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
img = <PIL.Image.Image image mode=RGB size=100x100 at 0x7FAC861DADA0>
hue_factor = -0.020240534096956253
@torch.jit.unused
def adjust_hue(img: Image.Image, hue_factor: float) -> Image.Image:
if not (-0.5 <= hue_factor <= 0.5):
raise ValueError(f"hue_factor ({hue_factor}) is not in [-0.5, 0.5].")
if not _is_pil_image(img):
raise TypeError(f"img should be PIL Image. Got {type(img)}")
input_mode = img.mode
if input_mode in {"L", "1", "I", "F"}:
return img
h, s, v = img.convert("HSV").split()
np_h = np.array(h, dtype=np.uint8)
# uint8 addition take cares of rotation across boundaries
with np.errstate(over="ignore"):
> np_h += np.uint8(hue_factor * 255)
E OverflowError: Python integer -5 out of bounds for uint8
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/torchvision/transforms/_functional_pil.py:114: OverflowError
It's not possible for your tests to pass without waiting for torchvision, but it is possible for the next release to be compatible with numpy 2 (futureproof). This way, as soon as torchvision makes a new release, the last month of lightly releases will already immediately support numpy 2.
We appreciate your input. However, relaxing the numpy version requirement again will lead to more broken installations, which we want to avoid. We've chosen to keep numpy constrained to <2.0
for the time being.
For the moment, there is no torchvision version compatible with numpy 2 thus we restricted the requirements to not use numpy 2: https://github.com/lightly-ai/lightly/pull/1562
Once a compatible torchvision version is released, we can have a look again.
Error using lightly with numpy 2.0
Numpy 2.0.0 was released on June 16th 2024 and does not work with lightly.
Using numpy==2.0.0 and lightly==1.5.6 and python==3.10.8:
Reproduce
Run in a new venv, such that numpy 2.0 is installed:
Workaround
Just install an older numpy version, e.g. using
pip install numpy==1.26
.