Comments (5)
I ran into the same problem. My solution is to remove the boxes that are None
and delete the corresponding images. I achieved this by returning the images from this function back to forward, like so:
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 select_boxes
function (omitted everything before if batch_mode
because nothing changed there)
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
from facenet-pytorch.
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.
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)
This code throws the error like
lib\site-packages\facenet_pytorch\models\utils\detect_face.py", line 359, in extract_face
margin * (box[2] - box[0]) / (image_size - margin),
TypeError: 'float' object is not subscriptable
Can you check it on your side?
from facenet-pytorch.
I would've expected that this doesn't affect a single image because of the if batch_mode:
check in the original code. I don't need to process a single image so I'll just use the solution I posted. But I guess it should be an easy fix if you debug the code a bit.
from facenet-pytorch.
The returned image value you create seems to pass the if batch_mode:
So it doesn't recognize the single image and batch group. Could you please update your code for that?
from facenet-pytorch.
Sorry, I don't have time for that, you'll have to fix it yourself (and you seem to be on the right track).
from facenet-pytorch.
Related Issues (20)
- Unexpected EOF Error for Resnet
- output embeddings dimension is weird HOT 1
- ONNX conversion HOT 3
- γ...'aten::nonzero' is not currently supported...γon M1
- Can not download the checkpoint in Remote Ubuntu machine
- Original FaceNet model? HOT 1
- how to github folder import HOT 1
- resize of non-square bounding boxes HOT 1
- ValueError with new numpy version for MTCNN HOT 5
- How to train and return 128 embedding? HOT 2
- memory leak in detect_face? HOT 3
- Extremely low LFW accuracy HOT 1
- MTCNN conversion to ONNX HOT 1
- Howo to recognize more than one face on one image? HOT 1
- A lot of false positives
- Wrong detected face saved
- image clustering according to the faces they contain
- segmentation fault on Apple M1
- Fine-tuning and retraining of the model HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facenet-pytorch.