get_features.py 796 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/python2
  2. import argparse
  3. import itertools
  4. import os
  5. import time
  6. import cv2
  7. import numpy
  8. import openface
  9. numpy.set_printoptions(precision=2)
  10. net = openface.TorchNeuralNet("nn4.small2.v1.t7", 96)
  11. def get_features(img, bb):
  12. start = time.time()
  13. alignedFace = align.align(96, img, bb,
  14. landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
  15. if alignedFace is None:
  16. raise Exception("Unable to align image: {}".format(imgPath))
  17. print(" + Face alignment took {} seconds.".format(time.time() - start))
  18. start = time.time()
  19. rep = net.forward(alignedFace)
  20. print(" + OpenFace forward pass took {} seconds.".format(time.time() - start))
  21. print("Representation:")
  22. print(rep)
  23. print("-----")
  24. print()
  25. return rep