Git Product home page Git Product logo

facenet-pytorch's People

Contributors

aryansoman avatar grjhuard avatar jdongca2003 avatar ldulcic avatar matthijsburgh avatar mawanda-jun avatar modemn avatar n1mmy avatar nscozzaro avatar psushi avatar rickygao avatar timesler avatar tokudayo avatar yuan2001425 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facenet-pytorch's Issues

Triplet Loss or Softmax

May I know if the embedding part is trained using triplet loss? or softmax cross-entropy instead? seeing that the pre-trained model includes also a softmax classifier. thank you~

ModuleNotFoundError: No module named 'facenet_pytorch' but I installed it with sudo -H pip3

In Ubuntu 18.04.02 Server Edition with Python 3.7.3 and pip 19.0.3 , I installed facenet-pytorch with pip3:

marco@pc:~/python3venvironments/pytorch-venv/facenet_pytorch$ sudo -H pip3 install facenet-
  pytorch
Collecting facenet-pytorch
  Using cached https://files.pythonhosted.org/packages/c3/73 
    /7efe44bce34b27e4d2fc32b184478d6a9066a7d111d6499546a30183cb13/facenet_pytorch-
    0.1.0-py3-none-any.whl
Requirement already satisfied: requests in /usr/local/lib/python3.7/site-packages (from facenet-
  pytorch) (2.22.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (from facenet-
  pytorch) (1.17.0)
Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/site-packages (from 
  facenet-pytorch) (4.1.0.25)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7
  /site-packages (from requests->facenet-pytorch) (1.25.3)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from 
  requests->facenet-pytorch) (2019.6.16)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages 
  (from requests->facenet-pytorch) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.7/site-packages (from 
  requests->facenet-pytorch) (2.8)
Installing collected packages: facenet-pytorch
Successfully installed facenet-pytorch-0.1.0

In the empty file infer.py I just added this line:

from facenet_pytorch import MTCNN, InceptionResnetV1

marco@pc:~/python3venvironments/pytorch-venv/facenet_pytorch$ python3 infer.py 
Traceback (most recent call last):
  File "infer.py", line 1, in <module>
    from facenet_pytorch import MTCNN, InceptionResnetV1
ModuleNotFoundError: No module named 'facenet_pytorch'

While trying to install facenet_pytorch with pip (python2) :

marco@pc:~/python3venvironments/pytorch-venv/facenet_pytorch$ sudo -H pip install facenet-pytorch
[sudo] password for marco: 
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your  
  Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for  
  Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest
  /development/release-process/#python-2-support
Collecting facenet-pytorch
  Downloading https://files.pythonhosted.org/packages/ea/6a/ 
    f7b104f7a0493fb9e6801e93102710af011cd9e1a7abb8525503549807b8/facenet-pytorch-
      0.1.0.tar.gz (1.9MB)
     |████████████████████████████████| 1.9MB 8.4MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-
       Y4XgoJ/facenet-pytorch/setup.py'"'"'; __file__='"'"'/tmp/pip-install-Y4XgoJ/facenet-pytorch
       /setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', 
      '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
     cwd: /tmp/pip-install-Y4XgoJ/facenet-pytorch/
    Complete output (3 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    IOError: [Errno 2] No such file or directory: '/tmp/pip-install-Y4XgoJ/facenet-pytorch/setup.py'
    ----------------------------------------

How to solve the problem?
Looking forward to your kind help.
Marco

Python Package

Any chance of making this into a package?

I'd pull request but I'm not sure how hard it is to set that up or if you guys have to do it.

Add methods for model training

The repo currently only includes models (MTCNN and InceptionResnetV1). It would be good to add code for updating pretrained models given new data or different training hyperparameters.

How to setup this project on windows?

Hello, I've cloned this repo, but is there any command to run this project, I've installed the python along with the anaconda, conda, but can't figure out how to run its test examples, if there is any test examples please help me step by step.

Kind Regards

How to interpret the output's value if the pictures refer to the same person?

I downloaded from here https://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html the AT&T database of faces, and I ran facenet-pytorch face detection and recognition pipeline : https://github.com/timesler/facenet-pytorch/blob/master/examples/infer.ipynb against the first set, s1, of faces refering to the same person:

Running on device: cpu
Face detected with probability: 0.999592
Face detected with probability: 0.999920
Face detected with probability: 0.996028
Face detected with probability: 0.995523
Face detected with probability: 0.999048
Face detected with probability: 0.999714
Face detected with probability: 0.999632
Face detected with probability: 0.999517
Face detected with probability: 0.999190
Face detected with probability: 0.986400
          s1        s1        s1        s1        s1        s1        s1        s1        s1        s1
s1  0.000000  0.782448  0.722293  0.665322  0.737728  0.648552  0.570795  0.704010  0.575219 
0.840837
s1  0.782448  0.000000  0.810834  0.763292  0.909566  0.638656  0.799031  0.800380  0.727899 
  1.042302
s1  0.722293  0.810834  0.000000  0.761772  0.893338  0.750267  0.734262  0.835646  0.819492 
  0.872905
s1  0.665322  0.763292  0.761772  0.000000  0.705478  0.719182  0.782794  0.754747  0.669086 
  0.812021
s1  0.737728  0.909566  0.893338  0.705478  0.000000  0.807325  0.617580  0.793141  0.574466 
  0.787223
s1  0.648552  0.638656  0.750267  0.719182  0.807325  0.000000  0.700938  0.780042  0.625027
  0.894988
s1  0.570795  0.799031  0.734262  0.782794  0.617580  0.700938  0.000000  0.724698  0.661852 
  0.873944
s1  0.704010  0.800380  0.835646  0.754747  0.793141  0.780042  0.724698  0.000000  0.644886 
  0.775929
s1  0.575219  0.727899  0.819492  0.669086  0.574466  0.625027  0.661852  0.644886  0.000000 
  0.773145
s1  0.840837  1.042302  0.872905  0.812021  0.787223  0.894988  0.873944  0.775929  0.773145 
  0.000000

Why are there such high values, for example between the 2nd and the 5th pictures : 0.909566, or the 2nd and the 10th pictures: 1.042302 ? Shouldn't be all the values rather low being the pictures of the same person? The minimum values are around 0.5, not less: 0.570795, 0.575219, 0.574466
How to interpret then these values?

Marco

No module named 'facenet_pytorch' but it seems indeed installed

I'm in this python3 virtualenv:

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pyenv virtualenvs
  3.7.3/envs/facenet_pytorch (created from /home/marco/.pyenv/versions/venv373)
  3.7.3/envs/venv373 (created from /home/marco/.pyenv/versions/3.7.3)
* facenet_pytorch (created from /home/marco/.pyenv/versions/venv373)
  venv373 (created from /home/marco/.pyenv/versions/3.7.3)

As far as I understand, the required module is already installed:

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pip3 install facenet_pytorch
Requirement already satisfied: facenet_pytorch in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (2.2.8)
Requirement already satisfied: requests in /home/marco/.pyenv/versions/3.7.3 
/envs/facenet_pytorch/lib/python3.7/site-packages (from facenet_pytorch) (2.23.0)
Requirement already satisfied: numpy in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from facenet_pytorch) (1.18.1)
Requirement already satisfied: chardet<4,>=3.0.2 in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from requests->facenet_pytorch) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from requests->facenet_pytorch) (2.9)
Requirement already satisfied: certifi>=2017.4.17 in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from requests->facenet_pytorch) 
(2019.11.28)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/marco/.pyenv
/versions/3.7.3/envs/facenet_pytorch/lib/python3.7/site-packages (from 
requests->facenet_pytorch) (1.25.8)

And with pip freeze it seems indeed installed in its virtualenv:

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pip3 freeze --local
certifi==2019.11.28
chardet==3.0.4
facenet-pytorch==2.2.8
idna==2.9
numpy==1.18.1
requests==2.23.0
urllib3==1.25.8

But when I try to execute this one-line-code:

prova.py :

from facenet_pytorch import MTCNN

I get ModuleNotFoundError: No module named 'facenet_pytorch'

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3 prova.py 
Traceback (most recent call last):
  File "prova.py", line 1, in <module>
    from facenet_pytorch import MTCNN
ModuleNotFoundError: No module named 'facenet_pytorch'
  • pip3 version: pip-20.0.2
  • OS: Ubuntu 18.04.4 Desktop
  • python version: Python 3.7.4

How to solve the problem?

Marco

Whats the best margin to init a mtcnn detector?

I want to do face crop from images, and then feed to your pretrained model to get 512-d embedding.
Usually models are trained on aligned faces. So my question are:

  1. On the training dataset, whats the value of parameter margin to init a mtcnn detector? (MTCNN(margin=?))
  2. When doing inference, is it necessary to align the cropped faces? If so, whats the setting of that alignment?

Thanks for the help.

Error downloading pretrained models

the code:

resnet = InceptionResnetV1(pretrained='vggface2').eval()

the exception:

    333             with open(cached_file, 'wb') as f:
    334                 f.write(r.content)
--> 335         state_dict.update(torch.load(cached_file))
    336 
    337     mdl.load_state_dict(state_dict)

~/.conda/envs/pytorch/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    424         if sys.version_info >= (3, 0) and 'encoding' not in pickle_load_args.keys():
    425             pickle_load_args['encoding'] = 'utf-8'
--> 426         return _load(f, map_location, pickle_module, **pickle_load_args)
    427     finally:
    428         if new_fd:

~/.conda/envs/pytorch/lib/python3.7/site-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    601             f.seek(0)
    602 
--> 603     magic_number = pickle_module.load(f, **pickle_load_args)
    604     if magic_number != MAGIC_NUMBER:
    605         raise RuntimeError("Invalid magic number; corrupt file?")

UnpicklingError: invalid load key, '<'.

the downloaded file:

html

*Update: Testing at another time worked normally, I really don't know what google policy for virus scanning on google drive files

Poor performance speed on CPU

I followed this part in the README and executed the kaggle notebook for performance comparison.
I'm using MacBook Pro with the following processor : 2.6 GHz 6-Core Intel Core i7.

The facenet-pytorch was the slowest detector (by far), as opposed to the results shown on your readme. Can you explain this surprising difference when switching from GPU to CPU ?

I can't add photos so i will just copy the output from the notebook:

facenet-pytorch

Detecting faces in 540x960 frames, 109.412 seconds
Detecting faces in 720x1280 frames, 180.797 seconds
Detecting faces in 1080x1920 frames, 298.694 seconds

facenet-pytorch (non batched)

Detecting faces in 540x960 frames, 79.293 seconds
Detecting faces in 720x1280 frames, 127.121 seconds
Detecting faces in 1080x1920 frames, 239.866 seconds

dlib

Detecting faces in 540x960 frames, 10.327 seconds
Detecting faces in 720x1280 frames, 18.395 seconds
Detecting faces in 1080x1920 frames, 38.444 seconds

mtcnn package

Detecting faces in 540x960 frames, 43.172 seconds
Detecting faces in 720x1280 frames, 71.451 seconds
Detecting faces in 1080x1920 frames, 146.714 seconds

Computing equivalent tensors from mtcnn tensor vs loading aligned images from disk

Originally I was going to post this as an issue, but in the process I figured something out so I will leave it here to help anyone attempting the same thing.

I wanted to compute my aligned images and store them to disk so that I could compute facenet embeddings later. Basically doing the alignment step from facenet where you align all of vggface2 before training the model. I was having some issues since it doesn't seem to be explained anywhere, so lets take a look at an example...

Originally I was saving as a jpg instead of png. Also you need to use fixed_image_standardization as preprocessing for the tensor after loading from disk.

from facenet_pytorch import MTCNN, InceptionResnetV1, fixed_image_standardization
# other imports not from facenet_pytorch...

device = torch.device('cuda')
mtcnn = MTCNN(image_size=160, margin=44)
inception = InceptionResnetV1(pretrained='vggface2').eval().to(device)

# can have whatever extension (mine was jpg)
unaligned_image_path = '<path to an unaligned image>'
# should have png extension
aligned_image_path = '<path to save aligned image>'

img = Image.open(unaligned_image_path)
img_tensor = mtcnn(img, save_path=aligned_image_path)

# create embedding from mtcnn output
img_tensor = mtcnn(img).unsqueeze(0).to(device)
emb_tensor = inception(img_tensor)
emb = emb_tensor.detach().cpu()

# create embedding from loading aligned image from disk
img_a = cv2.imread(aligned_image_path, 1)
img_a = cv2.cvtColor(img_a, cv2.COLOR_BGR2RGB).transpose((2,0,1))
img_a_tensor = torch.from_numpy(img_a).float().to(device).unsqueeze(0)
img_a_tensor = fixed_image_standardization(img_a_tensor)
emb_tensor = inception(img_a_tensor)
emb_a = emb_tensor.detach().cpu()

print((emb - emb_a).norm())
tensor(0.)

If you save the aligned image as jpg the distance will not be 0.
Also note you need to using fixed_image_standardization on the aligned image tensor.

@timesler Might be worth making a pr to show this in examples unless it's already in here, and I never found it. Feel free to close this issue. Figured it could help others if they are trying similar things.

Raise Exception("MTCNN batch processing only compatible with equal-dimension images.")

Today I upgraded PyTorch and libtorch to the fresh 1.5 release .

mtcc.py :

import torch
import torchvision
from facenet_pytorch import MTCNN, InceptionResnetV1

device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

mtcnn_module = 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
        )
sm_mtcc = torch.jit.script(mtcnn_module)

And now I'm getting this new error:

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3 ./mtcc.py 
Traceback (most recent call last):
  File "./mtcc.py", line 15, in <module>
    sm_mtcc = torch.jit.script(mtcnn_module)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1261, in 
script
    return torch.jit._recursive.create_script_module(obj, 
torch.jit._recursive.infer_methods_to_compile)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 305, in 
create_script_module
    return create_script_module_impl(nn_module, concrete_type, stubs_fn)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 361, in 
create_script_module_impl
    create_methods_from_stubs(concrete_type, stubs)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 279, in 
create_methods_from_stubs
    concrete_type._create_methods(defs, rcbs, defaults)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 587, in 
compile_unbound_method
    create_methods_from_stubs(concrete_type, (stub,))
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 279, in 
create_methods_from_stubs
    concrete_type._create_methods(defs, rcbs, defaults)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 568, in 
try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1287, in 
script
    ast = get_jit_def(obj)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 173, in 
get_jit_def
    return build_def(ctx, py_ast.body[0], type_line, self_name)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 206, in 
build_def
    build_stmts(ctx, body))
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 129, in 
build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 129, in 
<listcomp>
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 181, in 
__call__
    return method(ctx, node)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 364, in 
build_If
    build_stmts(ctx, stmt.orelse))
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 129, in 
build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 129, in 
<listcomp>
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 181, in 
__call__
    return method(ctx, node)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 362, in 
build_If
    return If(r, build_expr(ctx, stmt.test),
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 181, in 
__call__
    return method(ctx, node)
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 455, in 
build_Call
    args = [build_expr(ctx, py_arg) for py_arg in expr.args]
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 455, in 
<listcomp>
    args = [build_expr(ctx, py_arg) for py_arg in expr.args]
  File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 180, in 
__call__
    raise UnsupportedNodeError(ctx, node)
torch.jit.frontend.UnsupportedNodeError: GeneratorExp aren't supported:
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/models/utils
/detect_face.py", line 19
        if not isinstance(imgs, (list, tuple)):
            imgs = [imgs]
        if any(img.size != imgs[0].size for img in imgs):
               ~ <--- HERE
            raise Exception("MTCNN batch processing only compatible with equal-dimension 
images.")
        imgs = np.stack([np.uint8(img) for img in imgs])
'MTCNN.detect' is being compiled since it was called from 'MTCNN.forward'
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/models/mtcnn.py", 
line 247
        # Detect faces
        #with torch.no_grad():
        batch_boxes, batch_probs = self.detect(img)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        #batch_boxes = batch_boxes.detach()
        #batch_probs = batch_probs.detach()

How to solve the problem?
Looking forward to your kind help.
Marco

Perform Transfer Learning on Facenet PyTorch

Hi. Thank you so much for this excellent work.

I would like to perform transfer learning and finetune to a similar facial expression task where there are only 7 output classes. How can I modify the last layer of Inception VGGFace2?

Since I do not fully understand the last few layers, I run into some bugs.
I see the last few layers are FC ->AveragePool -> BN -> Logistic. I do not know which one I should modify. Both replacing the last one or replace starting FC do not work...

Could you please give me some guidance?

labels for vggface2 model

Hi
when I do classification with the pretrained vggface2 model, how do I match a probability to a name? do you have a list of labels for the trained model?

Thanks

Implement alternative detection algorithms

As highlighted in #10, the current MTCNN design is appropriate for the project while a single detection method is implemented, but with multiple, it makes more sense to separate the return of bounding boxes and confidences from the cropping of images.

Should also think about returning facial landmarks to implement face alignment following detection.

Retinaface is probably the best option to start with.

Keeping aspect ratio of extracted face image as is when saving

We can pass optional argument in extract_faces method to keep face image aspect ratio as is instead of resizing it to square. That way saved images would not have distortion effects of making image square.

I can work on a PR for this, if it makes sense!

The default postprocessing of MTCNN is not in accordance with the original facenet tensorflow repository

From my understanding, the original facenet tensorflow repository was trained by preprocessing the image with a fixed image standardization (more details here :
https://github.com/davidsandberg/facenet/wiki/Training-using-the-VGGFace2-dataset)

Implementation of fixed standardization in the tensorflow repository :
https://github.com/davidsandberg/facenet/blob/096ed770f163957c1e56efa7feeb194773920f6e/src/facenet.py#L120

The issue is that the default postprocessing of MTCNN is prewhitening (https://github.com/timesler/facenet-pytorch/blob/master/models/mtcnn.py#L280), which corresponds to the older preprocessing used in the tensorflow repository.

The default postprocessing should be the fixed image standardization

memory leak

Hello, Im facing a memory leak and I can't find out why. I am simply looping through a lot of images and it gradually fills all my memory, this is my setup:
Version facenet-pytorch==2.0.1

mtcnn = MTCNN(image_size=64, keep_all=True)
resnet = InceptionResnetV1(pretrained='vggface2').eval()

for nth, img_path in enumerate(img_paths):
    img = Image.open(img_path.resolve())
    boxes, probs = mtcnn.detect(img)

Implement alternative detection algorithms

As highlighted in #10, the current MTCNN design is appropriate for the project while a single detection method is implemented, but with multiple, it makes more sense to separate the return of bounding boxes and confidences from the cropping of images.

Should also think about returning facial landmarks to implement face alignment following detection.

Facial landmark?

Does this project support facial landmark detection?
I see word "align" in your file, but I don't find the relevant code.

Enable option for batch processing in MTCNN

MTCNN is difficult to parallelize due to the fact that it operates on raw images, which typically have variable dimension, and processes the output of the various p-, r-, and o-nets in loops. However, it should be possible to, in part, process images in batches when input images are resized to have the same dimension prior to detection.

Alternatively, the user could group images in their dataset that happen to have the same size and pass them to MTCNN together. Since most of the time is spent passing single image tensors through convolutional layers, it is likely that batch processing will result in substantial speed-ups.

Problem with ResNent

Hi, When I want to initialise ResNet, I have this problem.

image

Could You explain what does it mean?

Thanks!

MTCNN batching bug

Inputting the batch of 1280x720 images to MTCNN, the PIL format of the images has the width of 1280 and the height of 720, however after converting images to tensors in detect_face function on line 16, the wo is 720 and ho is 1280 which is flipped.

Then you proceed to concatenate the batch on the shorter side, in my case (batch 16) to [1,3,11520,1280] tensor. Which is in my view an arbitrary decision and it does not really matter which side is height or width.

However, come to the splitting the detected boxes into the batch on the lines 118-125, you choose the correct axis but incorrect dimension, because you pick the max(wo, ho) where in fact it needs to be a min(wo,ho), as you previously chose to concatenate on the shorter side.

I don't really have the problem with mixing H, W naming as I know that it is hard to be consistent while working with pytorch, cv2 and PIL, but it made it harder to find the bug.

how to upload my own dataset ?

thanks for this repo , i've a problem , how to upload my own dataset for resnet? does inception resnet with resnet are the same thing ?!
im new to nn
thanks for your advice ..

The input size of InceptionResnetV1

Thanks for your great work,when I run your code, I find something wrong, the output size of MTCNN is 160 * 160 and put this image to InceptionResnetV1, it wil return a RuntimeError said Output size is too small at x = self.avgpool_1a(x) in inception_resnet_v1.py line 270, so I changed the output size of MTCNN to 299 * 299,it works.
I want to know if I am doing the right thing or there are another way to fix this.

InceptionResnetV1 last layers

Hi Tim, thank you for the great code.

I try to make sense of the output with classify = True of InceptionResnetV1 and things do not sum up for me. So I looked at the TF code that you reference, and I have a couple of question, can you please help me to figure that out

  1. The code that I am looking at is this for the model and this for the training and the classification layer. Why do you use self.last_bn, it is not mentioned in the TF code. I assume every slim.fully_connected comes with a batch norm (where is it defined?), but how do you copy the weights then? Some black magic is happenning :)

  2. You call x = F.normalize(x, p=2, dim=1) unconditionally, but it seems like the TF version only does tf.nn.l2_normalize for embeddings, which are basically not used afterwards. I suspect there is a bug on your side, specifically in the finetuning notebook you apply torch.nn.CrossEntropyLoss() with that normalized activations, while the TF version does not do it. But in general x = self.logits(x) operation should be applied without normalization (again, according to the TF version).

Thanks,
Zahar

how to setup the pretrained model locally?

since the internet is too slow to download and frequently disconnected.

I could get the pretained model files some other way.

so how should I set it up locally?

Thank you!

Why does the network work best for 160x160 images ?

Can you please explain why the network would perform best for 160x160 images because I saw in the readme you had written since it was trained on 160x160 images. But can you give a detailed explanation of why is it so?

face_tracking.py example: NoneType' object has no attribute 'update

(OpenCV-) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3    
face_tracking.py 
Running on device: cpu
Tracking frame: 105
Done
<PIL.Image.Image image mode=RGB size=640x360 at 0x7F7AD8C86890>
Traceback (most recent call last):
  File "face_tracking.py", line 89, in <module>
    d.update(frames_tracked[i % len(frames_tracked)])
AttributeError: 'NoneType' object has no attribute 'update'

But I added the check "is not None":

# Add to frame list
if (frames) is not None:
    frames_tracked.append(frame_draw.resize((640, 360), Image.BILINEAR))

d = display.display(frames_tracked[0], display_id=True)
i = 1
try:
    while True:
        if(frames_tracked[i % len(frames_tracked)]) is not None:
            d.update(frames_tracked[i % len(frames_tracked)])
            i += 1
except KeyboardInterrupt:
    pass

behavior is incorrect as introduced

if self.num_classes != tmp_classes:

In this if statements, the dim of last fc layer is modified to the default num_classes(=1001). It is incompatible to the description:

# For a model pretrained on VGGFace2
model = InceptionResnetV1(pretrained='vggface2').eval()

As a result, the code above will not provide a classifier with 8631 output dim

Use it as a feature extrator

Hi Tim,
I would like to use this facenet as a feature extractor, i.e., delete the last few FC layers.
My Code
model = InceptionResnetV1(pretrained='vggface2', num_classes=8, classify=True).to(device)
print(model)
Result of last few layers:
(avgpool_1a): AdaptiveAvgPool2d(output_size=1)
(dropout): Dropout(p=0.6, inplace=False)
(last_linear): Linear(in_features=1792, out_features=512, bias=False)
(last_bn): BatchNorm1d(512, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
(logits): Linear(in_features=512, out_features=8, bias=True)
)'
Then, I delete the last FC and BN, so I do the following
model = nn.Sequential(*list(model.children())[:-2])
print("After Delete")
print(model)
Result of last few layers:
(13): AdaptiveAvgPool2d(output_size=1)
(14): Dropout(p=0.6, inplace=False)
(15): Linear(in_features=1792, out_features=512, bias=False)

Yes. This architecture is what I want.

But, if I want to use this pretrained weighted to get a 512d output, then I have the following error:
File "/home/xxx/anaconda3/envs/face_env/lib/python3.7/site/packages/torch/nn/functional.py", line 1371, in linear output = input.matmul(weight.t())
RuntimeError: size mismatch, m1: [3584 x 1], m2: [1792 x 512] at /opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/THC/generic/THCTensorMathBlas.cu:273

Softmax and Triplet loss

i tried to use the finetuning notebook, i trained the resnet model using softmax cross entropy for the first trial and with a triplet loss for the second both gived false embeddings. i changed the face detector method instead if mtcnn i used face alignment to crop the faces in case there is a side face the mtcnn would not recognize it. please confirm with me, does the face recognition model relate with the accuracy of the model?

MTCNN batch_processing throwing equal-dimesion error even though images are of same size

I have resized the images as mentioned before feeding to the model:

>>> resized_imgs.shape
torch.Size([32, 160, 160, 3])

However, the model still throws an error even though the images are of the same size!

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
 in 
----> 1 mtcnn(resized_imgs)

~\Miniconda3\envs\PytorchTest\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~\Miniconda3\envs\PytorchTest\lib\site-packages\facenet_pytorch\models\mtcnn.py in forward(self, img, save_path, return_prob)
    242         # Detect faces
    243         with torch.no_grad():
--> 244             batch_boxes, batch_probs = self.detect(img)
    245 
    246         # Determine if a batch or single image was passed

~\Miniconda3\envs\PytorchTest\lib\site-packages\facenet_pytorch\models\mtcnn.py in detect(self, img, landmarks)
    345                 self.pnet, self.rnet, self.onet,
    346                 self.thresholds, self.factor,
--> 347                 self.device
    348             )
    349 

~\Miniconda3\envs\PytorchTest\lib\site-packages\facenet_pytorch\models\utils\detect_face.py in detect_face(imgs, minsize, pnet, rnet, onet, threshold, factor, device)
     12         imgs = [imgs]
     13     if any(img.size != imgs[0].size for img in imgs):
---> 14         raise Exception("MTCNN batch processing only compatible with equal-dimension images.")
     15 
     16     imgs_np = np.stack([np.uint8(img) for img in imgs])

Exception: MTCNN batch processing only compatible with equal-dimension images.

Invalid syntax

Traceback (most recent call last):

File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 1, in
from facenet_pytorch import MTCNN, InceptionResnetV1, prewhiten, training

File "/home/flash/Desktop/akash/new/Pytorch-Facenet/facenet_pytorch/init.py", line 4, in
from .models.utils import training

File "/home/flash/Desktop/akash/new/Pytorch-Facenet/facenet_pytorch/models/utils/training.py", line 18
track_str = f'\r{self.mode} | {i + 1:5d}/{self.length:<5d}| '
^
SyntaxError: invalid syntax

No module named 'cv2' : not strictly related to facenet-pytorch but I kindly ask you any suggestions

Sorry Tim,
but still having issues with modules...

in OpenCV- virtual environment :

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pyenv virtualenvs
  3.7.3/envs/facenet_pytorch (created from /home/marco/.pyenv/versions/venv373)
  3.7.3/envs/list (created from /home/marco/.pyenv/versions/venv373)
  3.7.3/envs/OpenCV- (created from /home/marco/.pyenv/versions/3.7.3)
  3.7.3/envs/venv373 (created from /home/marco/.pyenv/versions/3.7.3)
  facenet_pytorch (created from /home/marco/.pyenv/versions/venv373)
  list (created from /home/marco/.pyenv/versions/venv373)
* OpenCV- (created from /home/marco/.pyenv/versions/3.7.3)
  venv373 (created from /home/marco/.pyenv/versions/3.7.3)

I've installed via pip3 the following modules:

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pip3 list
Package     Version 
--------------- --------
cycler          0.10.0  
kiwisolver      1.1.0   
matplotlib      3.2.0   
numpy           1.18.1  
opencv-python   4.2.0.32
pip             20.0.2  
pyparsing       2.4.6   
python-dateutil 2.8.1   
scipy           1.4.1   
setuptools      40.8.0  
six             1.14.0  

But when I try to execute this one-line program:

prova.py : from facenet_pytorch import MTCNN
I get ModuleNotFoundError: No module named 'cv2'

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python ./prova.py 
Traceback (most recent call last):
  File "./prova.py", line 1, in <module>
    from facenet_pytorch import MTCNN
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/__init__.py", line 2, in  
<module>
    from .models.mtcnn import MTCNN, PNet, RNet, ONet, prewhiten, fixed_image_standardization
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/models/mtcnn.py", 
line 6, in <module>
    from .utils.detect_face import detect_face, extract_face
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/models/utils
/detect_face.py", line 5, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2'

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3 ./prova.py 
Traceback (most recent call last):
  File "./prova.py", line 1, in <module>
    from facenet_pytorch import MTCNN
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/__init__.py", line 2, in 
<module>
    from .models.mtcnn import MTCNN, PNet, RNet, ONet, prewhiten, fixed_image_standardization
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/models/mtcnn.py", 
line 6, in <module>
    from .utils.detect_face import detect_face, extract_face
  File "/home/marco/anaconda3/lib/python3.7/site-packages/facenet_pytorch/models/utils 
/detect_face.py", line 5, in <module>
    import cv2 
ModuleNotFoundError: No module named 'cv2'

I tried to install opencv with conda but it says "Found conflicts!"

(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ conda install -c conda-forge 
opencv 
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata  
source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: - 
Found conflicts! Looking for incompatible packages.

This can take several minutes. Press CTRL-C to abort.

Examining conflict for pytest-doctestplus importlib_metadata zipp pytest-astropy pytest-arraydiff
pytest-openfiles more-itertools anaconda pytest-remotedata pytest astropy:  12%| | 35/301 
[20:45<1:55:20, Examining conflict for pytest-doctestplus importlib_metadata zipp pytest-astropy 
pytest-arraydiff pytest-openfiles more-itertools anaconda pytest-remotedata pytest astropy:  12%| |
 36/301 [20:45<1:30:28, Examining conflict for pytest-doctestplus pluggy pytest-astropy pytest-
arraydiff pytest-openfiles pytest anaconda pytest-remotedata spyder astropy:  12%|█▉       
       | 36/301 [20:53<1:30:28, 20.48s/it]Examining conflict for nbformat pytest-doctestplus pytest-
    astropy pytest-arraydiff pytest-openfiles prometheus_client anaconda pytest-remotedata pytest 
    jsonschema astropy jupyterlab_server attrs:  12%| | Examining conflict for nbformat pytest-
doctestplus pytest-astropy pytest-arraydiff pytest-openfiles prometheus_client anaconda pytest-
remotedata pytest jsonschema astropy jupyterlab_server attrs:  13%|▏| Examining conflict for 
pytest-doctestplus ipykernel jsonschema astropy nbconvert pickleshare ipywidgets pytest-arraydiff 
path.py jupyter_console pytest spyder ipython pytest-astropy pathlib2 pytest-remoteExamining 
conflict for pytest-doctestplus ipykernel jsonschema astropy nbconvert pickleshare ipywidgets 
pytest-arraydiff path.py jupyter_console pytest spyder ipython pytest-astropy pathlib2 pytest-
remoteExamining conflict for pytest-doctestplus pytest-astropy pytest-arraydiff pytest-openfiles 
anaconda pytest-remotedata py pytest astropy:  13%|███▊                         | 39/301 [21:20<54:55,
 12.58s/it]Examining conflict for pytest-doctestplus packaging sphinx dask pytest-astropy pytest-
arraydiff pytest-openfiles pytest anaconda distributed pytest-remotedata spyder astropy bokeh 
numpydoc:  14%|▏| 41/301Examining conflict for pytest-doctestplus packaging sphinx dask pytest-
astropy pytest-arraydiff pytest-openfiles pytest anaconda distributed pytest-remotedata spyder 
astropy bokeh numpydoc:  14%|▏| 42/301Examining conflict for pytest-doctestplus ipython 
prompt_toolkit wcwidth pytest-arraydiff pytest-openfiles pytest-astropy anaconda jupyter_console 
pytest-remotedata pytest astropy:  14%|▏| 42/301 [21:51<4Examining conflict for pytest-
doctestplus ipython prompt_toolkit wcwidth pytest-arraydiff pytest-openfiles pytest-astropy 
anaconda jupyter_console pytest-remotedata pytest astropy:  14%|▏| 43/301 [21:51<4

I know it's not strictly realted to facenet-pytorch, but I kindly ask you any suggestions....

Marco

invalid argument 0: Sizes of tensors must match except in dimension 0

when i run aligned = torch.stack(aligned).to(device=device) embeddings = resnet(aligned).detach().cpu()
i get the following error

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 1 and 2 in dimension 1 at C:\w\1\s\windows\pytorch\aten\src\TH/generic/THTensor.cpp:612

Add package dependencies to pip setup

Currently, the main code in the repo can be used via pip install facenet-pytorch, but none of the dependencies are installed if necessary. This should be an easy change except for the possible exception of open-cv, which is not straightforward on all systems.

Bug in MTCNN batch prediction

If numbox is 0 before any stage (i.e., numbox == 0 in https://github.com/timesler/facenet-pytorch/blob/master/models/utils/detect_face.py#L50), a total_boxes of shape (0, 9) will be appended into batch_boxes.
In contrast, if numbox is non-zero, a total_boxes of shape (x, 5) will be appended (x depends on the following stages).
Thus, when constructing the final results (https://github.com/timesler/facenet-pytorch/blob/master/models/utils/detect_face.py#L135), np.array(batch_boxes) may throw a shape mismatched exception.

Loading TorchScript Module : class method not recognized during compilation

I know it's not strictly related to facenet-pytorch library, but I do hope that may be you or others can give me an help.

My objective is to use the following class which simply uses your excellent work:

from facenet_pytorch import MTCNN, InceptionResnetV1
import torch
from torch.utils.data import DataLoader
from torchvision import datasets
import numpy as np
import pandas as pd
import os

workers = 0 if os.name == 'nt' else 4

def collate_fn(x):
    return x[0]

def describe(x):
    print("Type: {}".format(x.type()))
    print("Shape/size: {}".format(x.shape))
    print("Values: \n{}".format(x))

class GetFaceEmbedding(torch.nn.Module):
    def __init__(self):
        super(GetFaceEmbedding, self).__init__()

    @classmethod
    def getFaceEmbedding(self, imagePath):

        device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
        print('Running on device: {}'.format(device))

        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
        )
        resnet = InceptionResnetV1(pretrained='vggface2').eval().to(device)
        dataset = datasets.ImageFolder(imagePath)
        dataset.idx_to_class = {i:c for c, i in dataset.class_to_idx.items()}
        loader = DataLoader(dataset, collate_fn=collate_fn, num_workers=workers)
        aligned = []
        names = []
        for x, y in loader:
            x_aligned, prob = mtcnn(x, return_prob=True)
            if x_aligned is not None:
                print('Face detected with probability: {:8f}'.format(prob))
                aligned.append(x_aligned)
                names.append(dataset.idx_to_class[y])
        aligned = torch.stack(aligned).to(device)
        embeddings = resnet(aligned).detach().cpu()
        return embeddings

With python it works fine:

(venv373) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3 .  
/getFaceEmbedding-01.py 
Running on device: cpu
Face detected with probability: 0.999430
Type: torch.FloatTensor
Shape/size: torch.Size([1, 512])
Values: 
tensor([[ 3.6307e-02, -8.8092e-02, -3.5002e-02, -8.2932e-02,  1.9032e-02,
          2.3228e-02,  2.4253e-02, -3.7844e-02, -6.8906e-02,  2.0351e-02,
         -6.7093e-02,  3.6181e-02, -2.5933e-02, -6.0015e-02,  2.6653e-02,
          9.4335e-02, -2.9241e-02, -2.8357e-02,  7.2207e-02, -3.7747e-02,
          6.3515e-03, -3.0220e-02, -2.4530e-02,  1.0004e-01,  6.6520e-02,
          ....
          3.2497e-02,  2.3421e-02, -5.3921e-02,  1.9589e-02, -2.8655e-03,
          1.3474e-02, -2.2743e-02,  3.2976e-02, -5.6658e-02,  2.0837e-02,
        -4.7152e-02, -6.5534e-02]])

Following the indications found here: https://pytorch.org/tutorials/advanced/cpp_export.html

I added to getFaceEmbedding.py these lines:

my_module = GetFaceEmbedding()
sm = torch.jit.script(my_module)
sm.save("annotated_get_face_embedding.pt")

I then saved the serialized file:

(venv373) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3 
./getFaceEmbedding.py

-rw-r--r-- 1 marco marco 1,4K mar 19 18:52 annotated_get_face_embedding.pt

And created this cpp file:

(venv373) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ nano 
faceEmbedding.cpp

#include <torch/script.h>
#include <iostream>
#include <memory>
#include <filesystem>

int main(int argc, const char* argv[]) {
    //if(argc != 3) {
    //    std::cerr << "usage:usage: faceEmbedding <path-to-exported-script-module> <path-to-
   // image-file> \n";
    //    return -1;
    //}

  torch::jit::script::Module module;
  try {
      // Deserialize the ScriptModule from a file using torch::jit::load().
      module = torch::jit::load(argv[1]);
      std::filesystem::path imgPath = argv[2];

      // Execute the model and turn its output into a tensor
      at::Tensor output = module.getFaceEmbedding(imgPath).ToTensor();
  }
  catch (const c10::Error& e) {
      std::cerr << "error loading the model\n";
      return -1;
  }
  std::cout << "ok\n";
} // end of main() function

But during the compilation phase I get this error :

(venv373) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ mkdir build
(venv373) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ cd build
(venv373) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples/build$ cmake 
-DCMAKE_PREFIX_PATH=/home/marco/PyTorchMatters/libtorch ..
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found torch: /home/marco/PyTorchMatters/libtorch/lib/libtorch.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/marco/PyTorchMatters/facenet_pytorch/examples/build

(venv373) (base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples/build$ cmake --build 
. 
--config Release
Scanning dependencies of target faceEmbedding
[ 50%] Building CXX object CMakeFiles/faceEmbedding.dir/faceEmbedding.cpp.o
    /home/marco/PyTorchMatters/facenet_pytorch/examples/faceEmbedding.cpp: In function ‘int 
main(int, const char**)’:
/home/marco/PyTorchMatters/facenet_pytorch/examples/faceEmbedding.cpp:20:34: error: ‘struct 
torch::jit::script::Module’ has no member named ‘getFaceEmbedding’
   20 |       at::Tensor output = module.getFaceEmbedding(imgPath).ToTensor();
      |                                  ^~~~~~~~~~~~~~~~
CMakeFiles/faceEmbedding.dir/build.make:62: recipe for target 'CMakeFiles/faceEmbedding.dir
/faceEmbedding.cpp.o' failed
make[2]: *** [CMakeFiles/faceEmbedding.dir/faceEmbedding.cpp.o] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/faceEmbedding.dir/all' failed
make[1]: *** [CMakeFiles/faceEmbedding.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

How to solve the problem?
Looking forward to your kind help.
Marco

Further documentation

Hi. Appriciated for the repo. It's very informative and provides a nice, easy to use pytorch library. However, I find documentations a bit insufficient. Especially if you could explain the test.py, it would be great!

Cheers!

Cannot Import facenet_pytorch

I am using Jupyter notebook on Windows. I have python 3.6.4, and I installed facenet_pytorch using
pip3 install facenet_pytorch
the installation was successful, but I still cannot import it. upon executing
from facenet_pytorch import MTCNN, InceptionResnetV1

I still get an error: No module named 'facenet_pytorch' (no other details)

Can anyone help me with this? Let me know if I need to provide other details.

MTCNN bounding boxes.

Hi @timesler, first of all, tnx a lot for this awesome library :)

Could MTCNN be changed in a way that it also returns bounding boxes of faces detected?
I'll submit a PR for this, check it out if you want this feature in MTCNN.

Fine-tuning & pre-whitening

Thanks @timesler for the great work! I was trying to fine-tune on a small dataset and noticed that the network overfits very quickly. I think it's useful to train only the last linear layer ("logits" in your code). This worked fine for me:

optimizer = optim.Adam(net.module.logits.parameters())

Unrelated-ly, the pre-whiten transform may be screwing up the identification a bit as it normalizes each face using its own mean & std-dev. In one of my test videos, an African guy is identified as a white guy. So using a standard pre-processing for all faces may be a good idea. I see there's a related pull-request. Maybe I will experiment a bit myself next week.

Thanks again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.