Skip to content

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

Open
@georgestanley

Description

@georgestanley

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.
cocodataset/cocoapi#624

Describe your environment

Windows 10
Pytorch 2.1.2+cu121
numpy 1.26.3

cc @datumbox @nairbv @fmassa @NicolasHug @YosuaMichael

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions