pytorch / tutorials

PyTorch tutorials.
https://pytorch.org/tutorials/
BSD 3-Clause "New" or "Revised" License
8.15k stars 4.05k forks source link

[BUG] - Deprecated numpy.float failing pycocotools files #2733

Open georgestanley opened 8 months ago

georgestanley commented 8 months ago

Add Link

https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html

Describe the bug

(On Widnows) The torchvision object detection tutorial fails when the main function doing the training is run. This is due to numpy removing support for numpy.float in version > 1.24.

Error:

AttributeError                            Traceback (most recent call last)
Cell In[11], line 65
     63     lr_scheduler.step()
     64     # evaluate on the test dataset
---> 65     evaluate(model, data_loader_test, device=device)
     67 print("That's it!")

File C:\***\pytorch_venv\lib\site-packages\torch\utils\_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File C:\***\engine.py:112, in evaluate(model, data_loader, device)
    109 coco_evaluator.synchronize_between_processes()
    111 # accumulate predictions from all images
--> 112 coco_evaluator.accumulate()
    113 coco_evaluator.summarize()
    114 torch.set_num_threads(n_threads)

File C:\***\coco_eval.py:51, in CocoEvaluator.accumulate(self)
     49 def accumulate(self):
     50     for coco_eval in self.coco_eval.values():
---> 51         coco_eval.accumulate()

File C:\***\pytorch_venv\lib\site-packages\pycocotools\cocoeval.py:378, in COCOeval.accumulate(self, p)
    375 tps = np.logical_and(               dtm,  np.logical_not(dtIg) )
    376 fps = np.logical_and(np.logical_not(dtm), np.logical_not(dtIg) )
--> 378 tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
    379 fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
    380 for t, (tp, fp) in enumerate(zip(tp_sum, fp_sum)):

File C:\***\pytorch_venv\lib\site-packages\numpy\__init__.py:338, in __getattr__(attr)
    333     warnings.warn(
    334         f"In the future `np.{attr}` will be defined as the "
    335         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    337 if attr in __former_attrs__:
--> 338     raise AttributeError(__former_attrs__[attr])
    340 if attr == 'testing':
    341     import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

There is another bug report open in pycocotools git repo which seems to be not maintained any longer. https://github.com/cocodataset/cocoapi/pull/624

Describe your environment

Windows 10 Pytorch 2.1.2+cu121 numpy 1.26.3

cc @datumbox @nairbv @fmassa @NicolasHug @YosuaMichael

georgestanley commented 8 months ago

For those facing this issue, a quick fix can be see here: https://github.com/cocodataset/cocoapi/pull/624#issuecomment-1370250263

jmarintur commented 7 months ago

Looking at the PR comments @georgestanley shared, cocoapi repo seems no longer maintained. @svekars, does it make sense to create a PR using the quick fix that @georgestanley is mentioning?