We’re rewarding the question askers & reputations are being recalculated! Read more.
2 deleted 1 character in body
source | link

I noticed that the face_recognition library itself is quite optimized to run on both multiple cpus and gpu as well. But I will try to give my two cents for your specific code here.

Typically, there are two steps when it comes to such applications.

There is the training step where you parse all the known_person images once, and build a data of face_encodings, and store them on the disk. Typically these encodings are much smaller than the image data itself in size and it is something you do once for all the known images. (if you add new known images, consider this as a recalibration step where you need to regenerate your encodings). This step is usually accepted to be time-consuming and not done very frequently.

Then there is the inference step, which is the compare_faces function. This is what you want to do several times. For this specific step you just need the new image and known_list(which is the trained data that you stored on disk ahead of time).

So to improve your library, I would suggest adding a 'train' function which allows a list of images. This list should then store the encodings in a format (compressed if you have several images).

Then the compare_faces function can be modified to take in the encodings data. You can split this into load step (in case you compressed the data) and then compare step. This allows application to load the data once, but infer several times.

In your code itself, the compare_faces can be improved already. It can be changed to:

def compare_faces(unknown_images, image_encodings_data):
  for image in unknown_images:
    unknown_data = create_face_comparison_encoding(image)
    # Note how compare_faces takes multiple encodings.
    results = face_recognition.compare_faces(image_encodings_data,unknown_data)
    if results.count(True) ==> 10:
      print("This person appears familiar!")
      print("Writing the faces to output folder!")
      recognize_faces(image)
    else:
      print("This doesn't appear to be familiar!")

Also, I find it strange that you do not return which face it actually matched to.

Please feel free to ignore me if this is no longer your concern :)

I noticed that the face_recognition library itself is quite optimized to run on both multiple cpus and gpu as well. But I will try to give my two cents for your specific code here.

Typically, there are two steps when it comes to such applications.

There is the training step where you parse all the known_person images once, and build a data of face_encodings, and store them on the disk. Typically these encodings are much smaller than the image data itself in size and it is something you do once for all the known images. (if you add new known images, consider this as a recalibration step where you need to regenerate your encodings). This step is usually accepted to be time-consuming and not done very frequently.

Then there is the inference step, which is the compare_faces function. This is what you want to do several times. For this specific step you just need the new image and known_list(which is the trained data that you stored on disk ahead of time).

So to improve your library, I would suggest adding a 'train' function which allows a list of images. This list should then store the encodings in a format (compressed if you have several images).

Then the compare_faces function can be modified to take in the encodings data. You can split this into load step (in case you compressed the data) and then compare step. This allows application to load the data once, but infer several times.

In your code itself, the compare_faces can be improved already. It can be changed to:

def compare_faces(unknown_images, image_encodings_data):
  for image in unknown_images:
    unknown_data = create_face_comparison_encoding(image)
    # Note how compare_faces takes multiple encodings.
    results = face_recognition.compare_faces(image_encodings_data,unknown_data)
    if results.count(True) == 1:
      print("This person appears familiar!")
      print("Writing the faces to output folder!")
      recognize_faces(image)
    else:
      print("This doesn't appear to be familiar!")

Also, I find it strange that you do not return which face it actually matched to.

Please feel free to ignore me if this is no longer your concern :)

I noticed that the face_recognition library itself is quite optimized to run on both multiple cpus and gpu as well. But I will try to give my two cents for your specific code here.

Typically, there are two steps when it comes to such applications.

There is the training step where you parse all the known_person images once, and build a data of face_encodings, and store them on the disk. Typically these encodings are much smaller than the image data itself in size and it is something you do once for all the known images. (if you add new known images, consider this as a recalibration step where you need to regenerate your encodings). This step is usually accepted to be time-consuming and not done very frequently.

Then there is the inference step, which is the compare_faces function. This is what you want to do several times. For this specific step you just need the new image and known_list(which is the trained data that you stored on disk ahead of time).

So to improve your library, I would suggest adding a 'train' function which allows a list of images. This list should then store the encodings in a format (compressed if you have several images).

Then the compare_faces function can be modified to take in the encodings data. You can split this into load step (in case you compressed the data) and then compare step. This allows application to load the data once, but infer several times.

In your code itself, the compare_faces can be improved already. It can be changed to:

def compare_faces(unknown_images, image_encodings_data):
  for image in unknown_images:
    unknown_data = create_face_comparison_encoding(image)
    # Note how compare_faces takes multiple encodings.
    results = face_recognition.compare_faces(image_encodings_data,unknown_data)
    if results.count(True) > 0:
      print("This person appears familiar!")
      print("Writing the faces to output folder!")
      recognize_faces(image)
    else:
      print("This doesn't appear to be familiar!")

Also, I find it strange that you do not return which face it actually matched to.

Please feel free to ignore me if this is no longer your concern :)

1
source | link

I noticed that the face_recognition library itself is quite optimized to run on both multiple cpus and gpu as well. But I will try to give my two cents for your specific code here.

Typically, there are two steps when it comes to such applications.

There is the training step where you parse all the known_person images once, and build a data of face_encodings, and store them on the disk. Typically these encodings are much smaller than the image data itself in size and it is something you do once for all the known images. (if you add new known images, consider this as a recalibration step where you need to regenerate your encodings). This step is usually accepted to be time-consuming and not done very frequently.

Then there is the inference step, which is the compare_faces function. This is what you want to do several times. For this specific step you just need the new image and known_list(which is the trained data that you stored on disk ahead of time).

So to improve your library, I would suggest adding a 'train' function which allows a list of images. This list should then store the encodings in a format (compressed if you have several images).

Then the compare_faces function can be modified to take in the encodings data. You can split this into load step (in case you compressed the data) and then compare step. This allows application to load the data once, but infer several times.

In your code itself, the compare_faces can be improved already. It can be changed to:

def compare_faces(unknown_images, image_encodings_data):
  for image in unknown_images:
    unknown_data = create_face_comparison_encoding(image)
    # Note how compare_faces takes multiple encodings.
    results = face_recognition.compare_faces(image_encodings_data,unknown_data)
    if results.count(True) == 1:
      print("This person appears familiar!")
      print("Writing the faces to output folder!")
      recognize_faces(image)
    else:
      print("This doesn't appear to be familiar!")

Also, I find it strange that you do not return which face it actually matched to.

Please feel free to ignore me if this is no longer your concern :)