12345678910111213141516171819202122232425262728293031 |
- #!/usr/bin/python2
- import argparse
- import itertools
- import os
- import time
- import cv2
- import numpy
- import openface
- numpy.set_printoptions(precision=2)
- net = openface.TorchNeuralNet("nn4.small2.v1.t7", 96)
- def get_features(img, bb):
- start = time.time()
- alignedFace = align.align(96, img, bb,
- landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
- if alignedFace is None:
- raise Exception("Unable to align image: {}".format(imgPath))
- print(" + Face alignment took {} seconds.".format(time.time() - start))
- start = time.time()
- rep = net.forward(alignedFace)
- print(" + OpenFace forward pass took {} seconds.".format(time.time() - start))
- print("Representation:")
- print(rep)
- print("-----")
- print()
- return rep
|