facenet-pytorch icon indicating copy to clipboard operation
facenet-pytorch copied to clipboard

torch.cat error with empty boxes

Open PaulLerner opened this issue 2 years ago • 2 comments

Hi, I have an error when no boxes are detected for the whole batch, even in the first stage (is that expected? I work with images where there may be no faces)

It is caused by facenet_pytorch/models/utils/detect_face.py:83 : boxes = torch.cat(boxes, dim=0)

If it is expected, I guess a simple fix would be to test if len(boxes) > 0 like in the other stages

Full traceback is https://gist.github.com/PaulLerner/9b3b6feb95065d8395b4db1dca76241b

PaulLerner avatar Jul 28 '21 09:07 PaulLerner

It happens with this image which has an unusual aspect ratio: image

PaulLerner avatar Sep 07 '21 09:09 PaulLerner

OK now I got it: it’s because the image height is so small (smaller than min_face_size) then in here https://github.com/timesler/facenet-pytorch/blob/master/models/utils/detect_face.py#L57 the scales list is empty, thus the boxes is also empty So a fix would be to check whether minl >= minsize (min_face_size name in detect_face)

PaulLerner avatar Sep 07 '21 09:09 PaulLerner