Skip to content

Instantly share code, notes, and snippets.

@ageitgey
Last active January 22, 2022 06:00
Embed
What would you like to do?

Before you start

Make sure you have python, OpenFace and dlib installed. You can either install them manually or use a preconfigured docker image that has everying already installed:

docker pull bamos/openface
docker run -p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash
cd /root/openface

Step 1

Make a folder called /training-images/ somewhere on your computer.

Step 2

Make a subfolder for each person you want to recognize. For example:

  • /training-images/will-ferrell/
  • /training-images/chad-smith/
  • /training-images/jimmy-fallon/

Step 3

Copy all your images of each person into the correct sub-folders

Step 4

Run the openface scripts from inside the openface root directory:

First, do pose detection and alignment:

./util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96

Second, generate the representations from the aligned images:

./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/

When you are done, the ./generated-embeddings/ folder will contain a csv file with the embeddings for each image.

@abhising10p14
Copy link

Finally I solved my issue. I am writing for those who might face the same problem.
What's the actual problem is that when we install the openface , it gets installed in the root directory and the line
/util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96
doesn't give any error but doesn't form any /aligned-images in the given path.
I copied the openface in my user directory and just altered few lines of the "/util/align-dlib.py"

in the line
29 modelDir = os.path.join(fileDir, '..', 'models')
changed it to
29 modelDir = os.path.join(fileDir, 'models')
after this is done, copy the "training-images" folder into this openface folder
Now from the dlib directory copy the "shape_predictor_68_face_landmarks.dat" into the folder "openface"
Now run
/util/align-dlib.py ./training-images/ align outerEyesAndNose ./aligned-images/ --size 96
and now you will find a folder /aligned-images in openface folder
Now if you run the 2nd line
./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/

you will get an error that you don't have torch installed in your system , so first install torch
to install torch type->
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; bash install-deps;
./install.sh

after torch is installed, if you run
./batch-represent/main.lua -outDir ./generated-embeddings/ -data ./aligned-images/
again you will encounter the error like

no field package.preload['csvigo']
no file '/root/.luarocks/share/lua/5.1/csvigo.lua'
no file '/root/.luarocks/share/lua/5.1/csvigo/init.lua'
no file '/root/torch/install/share/lua/5.1/csvigo.lua'
no file '/root/torch/install/share/lua/5.1/csvigo/init.lua'
no file './csvigo.lua'
no file '/root/torch/install/share/luajit-2.1.0-beta1/csvigo.lua'
no file '/usr/local/share/lua/5.1/csvigo.lua'
no file '/usr/local/share/lua/5.1/csvigo/init.lua'
no file '/root/.luarocks/lib/lua/5.1/csvigo.so'
no file '/root/torch/install/lib/lua/5.1/csvigo.so'
no file '/root/torch/install/lib/csvigo.so'
no file './csvigo.so'
no file '/usr/local/lib/lua/5.1/csvigo.so'
no file '/usr/local/lib/lua/5.1/loadall.so'

to remove this type
luarocks install cutorch
luarocks install csvigo
luarocks install dnn
and you are done

@Branham94
Copy link

Hello how can I run the script on windows?

@rehtseyyl
Copy link

How do I access the root directory? and what does the './' in "./util/align-dlib.py" mean?

@adityajha03
Copy link

how to proceed with docker on mac?
In particular how to do step 3?

@piyushbajaj0704
Copy link

piyushbajaj0704 commented May 10, 2018

Running "sudo apt install torch-trepl "helped me resolved my issue with " /usr/bin/env: ‘th’: No such file or directory ".
I also installed:
luarocks install csvigo
luarocks install dnn

@vinic15
Copy link

vinic15 commented Nov 11, 2018

I tried to run this code on windows environment .I have set up everything dlib and pytorch using anaconda torch,csvigo,dnn using luarorks
and the first part of aligning the images was a success, I used "python util/align-dlib.py training-images/ align outerEyesAndNose aligned-images/ --size 96" command in a conda environment and got the aligned images in "aligned-images" folder but the problem is I was unable to get the embeddings in the "generated-embeddings" folder i used the command "lua batch-represent/main.lua -outDir generated-embeddings/ -data aligned-images/" at first i got lots of errors like requred csvigo,dnn,nn etc.but after installing all those packages the command executed successfully but the folder "generated-embeddings" was not created ,I am not even getting any errors.can some one help me how to run this code successfully on a windows environment.

-Thanks

@nswarnkar
Copy link

Im sorry but after I run this it says
/root/torch/install/bin/luajit: /root/openface/batch-represent/dataset.lua:193: could not find any image file in the given input paths

I am wondering why this happens, and also, if I have the embeddings, how can I use this to test the videos or other images on the Internet?

May be you followed the exact steps( specially step2) The path given ( /training-images/will-ferrell/) is relative to root ("/") but in steps further , author assumed in current directory.( i.e. ./training-images/will-ferrell/, note the dot ahead).

@santosmaycow
Copy link

C:\Program Files (x86)\Lua\5.1\lua.exe: C:\Program Files (x86)\Lua\5.1\lua\paths\init.lua:1: module 'libpaths' not found:
no field package.preload['libpaths']
no file '.\libpaths.lua'
no file 'C:\Program Files (x86)\Lua\5.1\lua\libpaths.lua'
no file 'C:\Program Files (x86)\Lua\5.1\lua\libpaths\init.lua'
no file 'C:\Program Files (x86)\Lua\5.1\libpaths.lua'
no file 'C:\Program Files (x86)\Lua\5.1\libpaths\init.lua'
no file 'C:\Program Files (x86)\Lua\5.1\lua\libpaths.luac'
no file '.\libpaths.dll'
no file '.\libpaths51.dll'
no file 'C:\Program Files (x86)\Lua\5.1\libpaths.dll'
no file 'C:\Program Files (x86)\Lua\5.1\libpaths51.dll'
no file 'C:\Program Files (x86)\Lua\5.1\clibs\libpaths.dll'
no file 'C:\Program Files (x86)\Lua\5.1\clibs\libpaths51.dll'
no file 'C:\Program Files (x86)\Lua\5.1\loadall.dll'
no file 'C:\Program Files (x86)\Lua\5.1\clibs\loadall.dll'
stack traceback:
[C]: in function 'require'
C:\Program Files (x86)\Lua\5.1\lua\paths\init.lua:1: in main chunk
[C]: in function 'require'
C:\Program Files (x86)\Lua\5.1\lua\torch\init.lua:12: in main chunk
[C]: in function 'require'
...p\TCC\face_estudos\openface\batch-represent\main.lua:3: in main chunk
[C]: ?
what should i do on windows?

@Bishree
Copy link

Bishree commented Jul 12, 2021

Is there any model to get face embedding features?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment