TrackEval icon indicating copy to clipboard operation
TrackEval copied to clipboard

Replace deprecated NumPy aliases with builtin types

Open piotlinski opened this issue 2 years ago • 8 comments

NumPy 1.20 deprecates some of the aliases of the builtin types: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

With version 1.24 the aliases were removed; the change is necessary to keep TrackEval working with newer versions of NumPy.

I replaced np.int, np.float and np.bool aliases with builtin types according to the table in the deprecation note.

piotlinski avatar Feb 15 '23 19:02 piotlinski

The problem here is that pycocotools, which is used by this repo for MOTS stuff, also has this issue. While it isn't updated on both sides the numpy version cannot be upgraded so I see no way of merging this. And pycocotools doesn't seem to be mantained anymore :cry:. Last update was 3 years ago.

mikel-brostrom avatar Feb 16 '23 11:02 mikel-brostrom

I see. However the use of these aliases is not consistent throughout TrackEval and this PR addresses this issue, unifying the approach (there are multiple places in which Python types were already used). What is more, for those who use TrackEval without the functionalities of pycocotools (myself included), this allows to use newer versions of NumPy as well.

One way would be to create a fork of pycocotools, fix the issues and switch to the fork here. This seems to be a bit of a fuss though :/

piotlinski avatar Feb 17 '23 00:02 piotlinski

One way would be to create a fork of pycocotools, fix the issues and switch to the fork here. This seems to be a bit of a fuss though :/

Yup :disappointed:. But at some point I guess it has to be done as pycocotools will become unusable otherwise

mikel-brostrom avatar Feb 17 '23 06:02 mikel-brostrom

Came here looking to fix it myself because we need to update to Numpy 1.14, but then found this MR.

It's not preferable to stay tied to pycocotools if they are so far behind with Numpy. Perhaps creating a fork and updating it should be the way to go.

wilderrodrigues avatar Mar 06 '23 20:03 wilderrodrigues

Also, pycocotools uses np.float in 2 lines only.

https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/cocoeval.py#L378

I fixed it for me with this hack:

import numpy as np
from packaging import version

if version.parse(np.__version__) >= version.parse("1.24.0"):
    np.float = np.float32
    np.int = np.int32
    np.bool = bool

Added it just before the import to trackeval. But it would be awesome to see someone taking pycocotools over and updating it.

wilderrodrigues avatar Mar 06 '23 20:03 wilderrodrigues

these commands to patch from CLI worked for me

grep -rl np.int . | xargs sed -i 's/np.int/int/g'
grep -rl np.bool . | xargs sed -i 's/np.bool/bool/g'
grep -rl np.float . | xargs sed -i 's/np.float/float/g'

Dorozhko-Anton avatar Sep 13 '23 10:09 Dorozhko-Anton

these commands to patch from CLI worked for me

grep -rl np.int . | xargs sed -i 's/np.int/int/g'
grep -rl np.bool . | xargs sed -i 's/np.bool/bool/g'
grep -rl np.float . | xargs sed -i 's/np.float/float/g'

I went for exact this same solution @Dorozhko-Anton. It is the best option right now IMO, rather than waiting for all eternity for this to get merged :laughing:

mikel-brostrom avatar Oct 16 '23 14:10 mikel-brostrom

I have edited the comment. This repo uses pycocotools

and not the original coco: cocodataset

Therefore, we would just need to update the requirements to the latest pycocotools version. pycocotools==2.0.7

dzambrano avatar Mar 21 '24 09:03 dzambrano