Support
Quality
Security
License
Reuse
kandi has reviewed face_recognition and discovered the below as its top functions. This is intended to give you an instant insight into face_recognition implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
Find all the faces that appear in a picture:. Get the locations and outlines of each person's eyes, nose, mouth and chin.
See all related Code Snippets
QUESTION
cannot append results to lists on multiprocessing
Asked 2022-Mar-18 at 11:30This below code will generate face encodings using multiprocessing , i can able to print the encoding but the problem is the knownEncodings ,knownNames ,no_faces ,error_in_image all are empty after the execution. I know its due to multiprocessing , but not sure how to mitigate this.
import face_recognition
from imutils import paths
from multiprocessing import Pool
import pickle
import cv2
import os,sys,time
print("[INFO] quantifying faces...")
img_folder_path=sys.argv[1]
image_paths = list(paths.list_images(img_folder_path))
knownEncodings = []
knownNames = []
no_faces = []
error_in_image =[]
def create_encoding(imagePath):
print("[INFO] processing image...")
name = imagePath.split(os.path.sep)[-1]
image = cv2.imread(imagePath)
if image is None:
return
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# detect the (x, y)-coordinates of the bounding boxes
# corresponding to each face in the input image
boxes = face_recognition.face_locations(rgb)
# compute the facial embedding for the face
if len(boxes) != 0:
boxes = list(boxes[0])
encodings = face_recognition.face_encodings(image, [boxes])
for encoding in encodings:
knownEncodings.append(encoding)
knownNames.append(name)
else:
print("no face found" ,image_paths )
no_faces.append(image_paths )
# loop over the image paths with multiprocessing
start_time = time.time()
with Pool(8) as pool:
pool.map(create_encoding, image_paths )
end_time = time.time()
print(end_time - start_time)
# dump the facial encodings + names to disk
print("[INFO] serializing encodings...")
data = {"encodings": knownEncodings, "names": knownNames, "no_faces":no_faces,"error_in_image":error_in_image}
f_name = img_folder_path.replace("/","-")
print(f_name)
f = open(f"encodings_{f_name}.pickle", "wb")
f.write(pickle.dumps(data))
f.close()
ANSWER
Answered 2022-Mar-18 at 10:46You should not use list cross several processes. You can use multiprocessing.Queue or other Process safe models. How to use multiprocessing queue in Python?
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Find more information at:
Save this library and start creating your kit
See Similar Libraries in
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source