-
Notifications
You must be signed in to change notification settings - Fork 961
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
numpy throwing error in batch mode when some images do not contain a face #224
Comments
I ran into the same problem. My solution is to remove the boxes that are forward function # Detect faces
batch_boxes, batch_probs, batch_points = self.detect(img, landmarks=True)
# Select faces
if not self.keep_all:
img, batch_boxes, batch_probs, batch_points = self.select_boxes(
batch_boxes, batch_probs, batch_points, img, method=self.selection_method,
)
# Extract faces
faces = self.extract(img, batch_boxes, save_path)
if return_prob:
return faces, batch_probs
else:
return faces and the if batch_mode:
sanitized_selected_boxes = []
sanitized_selected_probs = []
sanitized_selected_points = []
for idx, box in enumerate(selected_boxes):
if box is None:
if isinstance(imgs, list):
imgs.pop(idx)
elif isinstance(imgs, np.ndarray):
imgs = np.delete(imgs, idx, 0)
elif isinstance(imgs, torch.Tensor):
imgs = torch.cat((imgs[:idx], imgs[idx+1:]), 0)
else:
raise TypeError("imgs must be a list, np.ndarray, or torch.Tensor")
else:
sanitized_selected_boxes.append(box)
sanitized_selected_probs.append(selected_probs[idx])
sanitized_selected_points.append(selected_points[idx])
selected_boxes = np.array(sanitized_selected_boxes)
selected_probs = np.array(sanitized_selected_probs)
selected_points = np.array(sanitized_selected_points)
else:
selected_boxes = selected_boxes[0]
selected_probs = selected_probs[0][0]
selected_points = selected_points[0]
return imgs, selected_boxes, selected_probs, selected_points |
Hi, @florianblume Your code fixed a certain issue when some images don't contain faces. However, it threw a new error when testing one image in the inference script.
This code throws the error like
Can you check it on your side? |
I would've expected that this doesn't affect a single image because of the |
The returned image value you create seems to pass the |
Sorry, I don't have time for that, you'll have to fix it yourself (and you seem to be on the right track). |
Hi, @beicodewarrior ! I faced with same problem. This is how i fixed it: mtcnn = MTCNN(
image_size=160, margin=0, min_face_size=20,
thresholds=[0.6, 0.7, 0.7], factor=0.709, post_process=True,
device=device
)
img = Image.open('1.jpg')
img_cropped = mtcnn([img]) |
I got this error message from this code
It appears to be similar to the one described in this resolved issue:
#206
I made the following changes to lines 444-446 in the file 'models/mtcnn.py'. These modifications ensure that when there are no faces detected in an image, the function returns None.
However, I'm uncertain if this fix might have adverse effects elsewhere in the codebase as I'm not familiar with it.
The text was updated successfully, but these errors were encountered: