From fa70227bd5f02209512f60bd10e7e66877fdb4f6 Mon Sep 17 00:00:00 2001 From: Tim Esler Date: Thu, 6 Apr 2023 10:07:15 -0700 Subject: [PATCH] numpy throwing deprecation warning for creating ndarray from nested sequences (#196) (#207) Numpy is throwing deprecation warnings for creating arrays from nested sequences on line 183 of detect_face.py and on lines 339, 340, 341 of mtcnn.py when running the example training script. The fix is to pass 'dtype=object' as a parameter when creating the ndarray. E.g., on line 339 of mtcnn.py np.array(boxes) becomes np.array(boxes, dtype=object) Co-authored-by: Markham Lee --- models/mtcnn.py | 6 +++--- models/utils/detect_face.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/mtcnn.py b/models/mtcnn.py index e2a7c83e..13b33a93 100644 --- a/models/mtcnn.py +++ b/models/mtcnn.py @@ -336,9 +336,9 @@ def detect(self, img, landmarks=False): boxes.append(box[:, :4]) probs.append(box[:, 4]) points.append(point) - boxes = np.array(boxes) - probs = np.array(probs) - points = np.array(points) + boxes = np.array(boxes, dtype=object) + probs = np.array(probs, dtype=object) + points = np.array(points, dtype=object) if ( not isinstance(img, (list, tuple)) and diff --git a/models/utils/detect_face.py b/models/utils/detect_face.py index 6c4a76d5..f5db6a40 100644 --- a/models/utils/detect_face.py +++ b/models/utils/detect_face.py @@ -180,7 +180,7 @@ def detect_face(imgs, minsize, pnet, rnet, onet, threshold, factor, device): batch_boxes.append(boxes[b_i_inds].copy()) batch_points.append(points[b_i_inds].copy()) - batch_boxes, batch_points = np.array(batch_boxes), np.array(batch_points) + batch_boxes, batch_points = np.array(batch_boxes, dtype=object), np.array(batch_points, dtype=object) return batch_boxes, batch_points