Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Numpy >= 1.24 #1110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions detector/tracker/tracker/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from tracker.utils import kalman_filter
import time

# np.float removed in Numpy 1.24
DTYPE_FLOAT = np.float if hasattr(np, "float") else float

def merge_matches(m1, m2, shape):
O,P,Q = shape
m1 = np.asarray(m1)
Expand Down Expand Up @@ -61,13 +64,13 @@ def ious(atlbrs, btlbrs):

:rtype ious np.ndarray
"""
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float)
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=DTYPE_FLOAT)
if ious.size == 0:
return ious

ious = bbox_ious(
np.ascontiguousarray(atlbrs, dtype=np.float),
np.ascontiguousarray(btlbrs, dtype=np.float)
np.ascontiguousarray(atlbrs, dtype=DTYPE_FLOAT),
np.ascontiguousarray(btlbrs, dtype=DTYPE_FLOAT)
)

return ious
Expand Down Expand Up @@ -101,10 +104,10 @@ def embedding_distance(tracks, detections, metric='cosine'):
:return: cost_matrix np.ndarray
"""

cost_matrix = np.zeros((len(tracks), len(detections)), dtype=np.float)
cost_matrix = np.zeros((len(tracks), len(detections)), dtype=DTYPE_FLOAT)
if cost_matrix.size == 0:
return cost_matrix
det_features = np.asarray([track.curr_feat for track in detections], dtype=np.float)
det_features = np.asarray([track.curr_feat for track in detections], dtype=DTYPE_FLOAT)
for i, track in enumerate(tracks):
cost_matrix[i, :] = np.maximum(0.0, cdist(track.smooth_feat.reshape(1,-1), det_features, metric))
return cost_matrix
Expand Down
4 changes: 3 additions & 1 deletion detector/tracker/tracker/multitracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from tracker.tracker import matching
from tracker.tracker.basetrack import BaseTrack, TrackState

# np.float removed in Numpy 1.24
DTYPE_FLOAT = np.float if hasattr(np, "float") else float

class STrack(BaseTrack):

def __init__(self, tlwh, score, temp_feat, buffer_size=30):

# wait activate
self._tlwh = np.asarray(tlwh, dtype=np.float)
self._tlwh = np.asarray(tlwh, dtype=DTYPE_FLOAT)
self.kalman_filter = None
self.mean, self.covariance = None, None
self.is_activated = False
Expand Down
4 changes: 3 additions & 1 deletion trackers/ReidModels/net_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from utils.log import logger

# np.float removed in Numpy 1.24
DTYPE_FLOAT = np.float if hasattr(np, "float") else float

class ConcatAddTable(nn.Module):
def __init__(self, *args):
Expand Down Expand Up @@ -127,7 +129,7 @@ def load_net(fname, net, prefix='', load_state_dict=False):
lr = h5f.attrs['learning_rates']
else:
lr = h5f.attrs.get('lr', -1)
lr = np.asarray([lr] if lr > 0 else [], dtype=np.float)
lr = np.asarray([lr] if lr > 0 else [], dtype=DTYPE_FLOAT)

return epoch, lr

Expand Down
5 changes: 4 additions & 1 deletion trackers/tracker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
from ReidModels.osnet_ain import osnet_ain_x1_0
from ReidModels.resnet_fc import resnet50_fc512

# np.float removed in Numpy 1.24
DTYPE_FLOAT = np.float if hasattr(np, "float") else float

class STrack(BaseTrack):
shared_kalman = KalmanFilter()

def __init__(self, tlwh, score, temp_feat, pose,crop_box,file_name,ps,buffer_size=30):

# wait activate
self._tlwh = np.asarray(tlwh, dtype=np.float)
self._tlwh = np.asarray(tlwh, dtype=DTYPE_FLOAT)
self.kalman_filter = None
self.mean, self.covariance = None, None
self.is_activated = False
Expand Down
13 changes: 8 additions & 5 deletions trackers/tracking/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from trackers.utils import kalman_filter
import time

# np.float removed in Numpy 1.24
DTYPE_FLOAT = np.float if hasattr(np, "float") else float

def merge_matches(m1, m2, shape):
O,P,Q = shape
m1 = np.asarray(m1)
Expand Down Expand Up @@ -61,13 +64,13 @@ def ious(atlbrs, btlbrs):

:rtype ious np.ndarray
"""
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float)
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=DTYPE_FLOAT)
if ious.size == 0:
return ious

ious = bbox_ious(
np.ascontiguousarray(atlbrs, dtype=np.float),
np.ascontiguousarray(btlbrs, dtype=np.float)
np.ascontiguousarray(atlbrs, dtype=DTYPE_FLOAT),
np.ascontiguousarray(btlbrs, dtype=DTYPE_FLOAT)
)

return ious
Expand Down Expand Up @@ -101,10 +104,10 @@ def embedding_distance(tracks, detections, metric='cosine'):
:return: cost_matrix np.ndarray
"""

cost_matrix = np.zeros((len(tracks), len(detections)), dtype=np.float)
cost_matrix = np.zeros((len(tracks), len(detections)), dtype=DTYPE_FLOAT)
if cost_matrix.size == 0:
return cost_matrix
det_features = np.asarray([track.curr_feat for track in detections], dtype=np.float)
det_features = np.asarray([track.curr_feat for track in detections], dtype=DTYPE_FLOAT)
for i, track in enumerate(tracks):
cost_matrix[i, :] = np.maximum(0.0, cdist(track.smooth_feat.reshape(1,-1), det_features, metric))
return cost_matrix
Expand Down
4 changes: 3 additions & 1 deletion trackers/utils/bbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import cv2

# np.float removed in Numpy 1.24
DTYPE_FLOAT = np.float if hasattr(np, "float") else float

def clip_boxes(boxes, im_shape):
"""
Expand Down Expand Up @@ -33,7 +35,7 @@ def clip_box(bbox, im_shape):


def int_box(box):
box = np.asarray(box, dtype=np.float)
box = np.asarray(box, dtype=DTYPE_FLOAT)
box = np.round(box)
return np.asarray(box, dtype=np.int)

Expand Down