Skip to content

Replace deprecated NumPy aliases with builtin types#117

Open
piotlinski wants to merge 1 commit into
JonathonLuiten:masterfrom
GallioPRO:master
Open

Replace deprecated NumPy aliases with builtin types#117
piotlinski wants to merge 1 commit into
JonathonLuiten:masterfrom
GallioPRO:master

Conversation

@piotlinski

Copy link
Copy Markdown

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.

@mikel-brostrom

mikel-brostrom commented Feb 16, 2023

Copy link
Copy Markdown

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 😢. Last update was 3 years ago.

@piotlinski

Copy link
Copy Markdown
Author

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 :/

@mikel-brostrom

mikel-brostrom commented Feb 17, 2023

Copy link
Copy Markdown

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 😞. But at some point I guess it has to be done as pycocotools will become unusable otherwise

@wilderrodrigues

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

@Dorozhko-Anton

Copy link
Copy Markdown

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'

@mikel-brostrom

mikel-brostrom commented Oct 16, 2023

Copy link
Copy Markdown

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 😆

@dzambrano

dzambrano commented Mar 21, 2024

Copy link
Copy Markdown

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

@discort

discort commented Jan 2, 2025

Copy link
Copy Markdown

@piotlinski @mikel-brostrom
Any plans to finish this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants