hukkelas / DSFD-Pytorch-Inference

A High-Performance Pytorch Implementation of face detection models, including RetinaFace and DSFD
Apache License 2.0
218 stars 58 forks source link

RuntimeWarning: overflow encountered in scalar multiply #31

Open cszygmtxst opened 1 year ago

cszygmtxst commented 1 year ago

img shape (1800, 2880, 3) n_anchors += x[0] x[1] len(min_sizes[0]) Traceback (most recent call last): File "test.py", line 29, in face_detect boxes = detector.detect(img) File "/lib/python3.8/site-packages/face_detection/base.py", line 56, in detect boxes = self.batched_detect(image, shrink) File "/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) File "/lib/python3.8/site-packages/face_detection/base.py", line 146, in batched_detect boxes = self._batched_detect(image) File "/lib/python3.8/site-packages/face_detection/base.py", line 126, in _batched_detect boxes = self._detect(image) File "/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(args, **kwargs) File "/lib/python3.8/site-packages/face_detection/retinaface/detect.py", line 120, in _detect priors = priorbox.forward() File "/lib/python3.8/site-packages/face_detection/retinaface/prior_box.py", line 43, in forward anchors = generate_prior_box( File "/lib/python3.8/site-packages/face_detection/retinaface/prior_box.py", line 26, in generate_prior_box anchors[idx_anchor:idx_anchor+4] = [cx, cy, s_kx, s_ky] ValueError: could not broadcast input array from shape (4,) into shape (0,)

hukkelas commented 1 year ago

Could you give a bit more information to reproduce this? E.g. your python/pytorch/numpy versions and operating system. Also, please provide the exact script you ran to reproduce this.

rogerhardt commented 1 week ago

Hello @hukkelas i am having the same issue on my new macOS Sonoma, using the RetinaNet detectors. Using the DSFDetector it works fine, but i need the RetinaNet for the speed. It worked fine the last time i used it, on my windows in may. Back then i installed via pip install face_detection, but this time i was getting the 410 gone error so i changed to install via the github installation

Python 3.12.7 pip3 pip 24.2 numpy 2.1.1 torchvision 0.19.1 torch 2.4.1

Here is the code i am using:

import cv2
import face_detection
import numpy as np
print(face_detection.available_detectors)
detector = face_detection.build_detector("RetinaNetMobileNetV1", confidence_threshold=.7, nms_iou_threshold=.3)

video_capture = cv2.VideoCapture("videos/video_1.mp4")
process_this_frame = True

while True:
    ret, frame = video_capture.read()
    detections = detector.detect(frame[:, :, ::-1])

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
rogerhardt commented 1 week ago

It was working fine for me back in May when i first installed it on my last computer. I tried downloading your github and running test.py, changing the detector to RetinaNet and a similar error occured with "negative dimensions not allowed"

rogerhardt commented 1 week ago

@hukkelas i discovered that resizing the video frame to 25% its size the script runs fine, but i need to use the full resolution for the best results (1920 * 1080)

Heres the full error with a print on the generate_prio_box

/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/retinaface/prior_box.py:11: RuntimeWarning: overflow encountered in scalar multiply
/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/retinaface/prior_box.py:12: RuntimeWarning: overflow encountered in scalar multiply
Feature_maps:  [[135 240]
 [ 68 120]
 [ 34  60]]
image_size:  [1080 1920]
steps:  [ 8 16 32]
min_sizes:  [[ 16  32]
 [ 64 128]
 [256 512]]
Traceback (most recent call last):
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/igreja/reconhecimento-facial-igreja/detection.py", line 22, in <module>
    detections = detector.detect(frame[:, :, ::-1])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/base.py", line 56, in detect
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/base.py", line 146, in batched_detect
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/base.py", line 126, in _batched_detect
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/retinaface/detect.py", line 120, in _detect
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/retinaface/prior_box.py", line 46, in forward
  File "/Users/rogermauriciogerhardt/Workspace/Personal/Projects/lib/lib/python3.12/site-packages/face_detection-0.2.1-py3.12.egg/face_detection/retinaface/prior_box.py", line 29, in generate_prior_box
ValueError: could not broadcast input array from shape (4,) into shape (0,)