OpenFace Face Matching with Django

237 views
Skip to first unread message

RON MICHAEL

unread,
Dec 20, 2016, 4:41:05 AM12/20/16
to CMU-OpenFace
Hello! I'm working on a site that requires facial recognition. I'm using Django 1.8.4. There was no documentation on how to use OpenFace's API. So what I tried doing was import the folder necessary for training, creating a classifier, and recognizing. The result was that I was able to train the images, create a classifier, and recognize them and return the results. Here's a sample code.

I simply call these functions in my queries. 
def align_faces(inputDir, outputDir):
os.system("./util/align-dlib.py"+ " " + inputDir + " " + "align outerEyesAndNose"+ " " + outputDir + " " +"--size 96")

def generate_embeddings_files(path, company):
os.system("./batch-represent/main.lua -outDir"+" "+path+" "+"-data ./aligned-images/"+company+"/")

def train_embeddings(company):
os.system("./demos/classifier.py train ./generated-embeddings/"+company+"/")

def predict_face(company, image_path):
conf = subprocess.check_output(["./demos/classifier.py", "infer", "./generated-embeddings/"+company+"/"+"classifier.pkl", image_path])
return conf
def generate_embeddings(request):
try:
data = req_data(request, True)
company = str(data["company"])
file_path = "./aligned-images/"
gen_emb_path = "./generated-embeddings/"+company+"/"

if os.path.exists(gen_emb_path): 
shutil.rmtree(gen_emb_path)

file_path = "./aligned-images/" + str(data["company"]) + "/" + "cache.t7" 
if os.path.exists(file_path):
os.remove(file_path)

generate_embeddings_files(gen_emb_path, company)

return HttpResponse("Success!", status=200)
except Exception as err:
print(err)
return HttpResponse(err, status=400)

def train_classifier(request):
try:
data = req_data(request, True)
company = str(data["company"])

train_embeddings(company)
return HttpResponse("Success!", status=200)
except Exception as err:
print(err

)


So right after I did this I updated my site which is running in Google Compute Engine. The result was that it was able to align the images, train them, but, it didn't produce a classifier.pkl. And when I tried recognizing the faces, the images did not appear. So my question is that is there any work around to this problem? Thanks! 



 

Brandon Amos

unread,
Dec 26, 2016, 3:47:59 PM12/26/16
to CMU-OpenFace
Hi, can you send the output of the os.system calls to OpenFace when executed on Google Compute Engine?

-Brandon.

RON MICHAEL

unread,
Dec 26, 2016, 9:52:58 PM12/26/16
to CMU-OpenFace
Hi Brandon! The output of the os.system is found in the image below.



def align_faces(inputDir, outputDir):
os.system("./util/align-dlib.py"+ " " + inputDir + " " + "align outerEyesAndNose"+ " " + outputDir + " " +"--size 96")



The output for the function align_faces outputs a folder containing all the aligned images.

def generate_embeddings_files(path, company):
os.system("./batch-represent/main.lua -outDir"+" "+path+" "+"-data ./aligned-images/"+company+"/")


The function generated_embeddings_files generates a the embeddings_files like the labels.csv and the reps.csv

def train_embeddings(company):
os.system("./demos/classifier.py train ./generated-embeddings/"+company+"/")

and lastly the train_embeddings function produces that classifier.pkl file. These are the results when run in the Google Compute Engine.

Brandon Amos

unread,
Dec 26, 2016, 9:55:50 PM12/26/16
to CMU-OpenFace
Hi, can you also send the terminal output of those calls?

-Brandon.
Message has been deleted

RON MICHAEL

unread,
Dec 26, 2016, 11:17:56 PM12/26/16
to CMU-OpenFace
Will these do? These are the results from training.

Brandon Amos

unread,
Dec 27, 2016, 11:25:18 AM12/27/16
to CMU-OpenFace
It looks like labels.csv is not being properly created or loaded. Can you check the contents of it and that it's trying to be loaded from the correct path?

-Brandon.

RON MICHAEL

unread,
Dec 27, 2016, 7:20:22 PM12/27/16
to CMU-OpenFace
Yeah my bad...I had that problem fixed already. Still though, running this on Google Cloud Engine, the results still don't show up

Brandon Amos

unread,
Dec 27, 2016, 8:35:07 PM12/27/16
to CMU-OpenFace
Yeah my bad...I had that problem fixed already.
 
Can you send the console output when running it with labels.csv fixed? There is probably another error message now.

-Brandon. 

RON MICHAEL

unread,
Dec 28, 2016, 1:28:03 AM12/28/16
to CMU-OpenFace

It's pretty much the same except without the errors. I was able to produce reps.csv, labels.csv, and classifier.pkl.

RON MICHAEL

unread,
Dec 30, 2016, 1:56:09 AM12/30/16
to CMU-OpenFace

Hey Bamos! I've posted my answer to your question. 
Reply all
Reply to author
Forward
0 new messages