Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Recommended Posts

Posted · Original PosterOP

Hi, I am building a face recognition program in python3.

I started with getting a face id program.

Then I added blinkdetection to insure that its a living person and not a photo.

Then I added a face detection model.

Then I came back to the face recognition part.

Turns out that 60% meens 60% unsure.

Now I am looking for a better face recognition program.

I heard that a face recognition program with deep learning will increase accurcy a lot.

I have googled it a lot but I still can't find a working program.

If someone has a solution/tip please comment below.

 

Thanks!

Link to post
Share on other sites
Posted · Original PosterOP

Thanks for the face detection code but it already had that. I was looking for a face recognition program with deep learning. And I found it yesterday. But there is one problem:

# python recognize_faces_image.py --encodings encodings.pickle --image examples/example_01.png 

# import the necessary packages
import face_recognition
import argparse
import pickle
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-e", "--encodings", required=True,
	help="path to serialized db of facial encodings")
ap.add_argument("-i", "--image", required=True,
	help="path to input image")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
	help="face detection model to use: either `hog` or `cnn`")
args = vars(ap.parse_args())

# load the known faces and embeddings
print("[INFO] loading encodings...")
data = pickle.loads(open(args["encodings"], "rb").read())

# load the input image and convert it from BGR to RGB
image = cv2.imread(args["image"])
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# detect the (x, y)-coordinates of the bounding boxes corresponding
# to each face in the input image, then compute the facial embeddings
# for each face
print("[INFO] recognizing faces...")
boxes = face_recognition.face_locations(rgb,
	model=args["detection_method"])
encodings = face_recognition.face_encodings(rgb, boxes)

# initialize the list of names for each face detected
names = []

# loop over the facial embeddings
for encoding in encodings:
	# attempt to match each face in the input image to our known
	# encodings
	matches = face_recognition.compare_faces(data["encodings"],
		encoding)
	name = "Unknown"

	# check to see if we have found a match
	if True in matches:
		# find the indexes of all matched faces then initialize a
		# dictionary to count the total number of times each face
		# was matched
		matchedIdxs = [i for (i, b) in enumerate(matches) if b]
		counts = {}

		# loop over the matched indexes and maintain a count for
		# each recognized face face
		for i in matchedIdxs:
			name = data["names"][i]
			counts[name] = counts.get(name, 0) + 1

		# determine the recognized face with the largest number of
		# votes (note: in the event of an unlikely tie Python will
		# select first entry in the dictionary)
		name = max(counts, key=counts.get)
	
	# update the list of names
	names.append(name)

# loop over the recognized faces
for ((top, right, bottom, left), name) in zip(boxes, names):
	# draw the predicted face name on the image
	cv2.rectangle(image, (left, top), (right, bottom), (0, 255, 0), 2)
	y = top - 15 if top - 15 > 15 else top + 15
	cv2.putText(image, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,
		0.75, (0, 255, 0), 2)

# show the output image
cv2.imshow("Image", image)
cv2.waitKey(0)

Line 32 where boxes is defined takes 28 seconds to define and that's way to long. Is there any way to define it outside the function or make the process faster?

My and goal is this: The camera sees a face( an other program), it calls the id function, the id function takes a picture and quickly1 ids the person. (There is more but that's irrelevant)

 

1.quickly = 2 to 10 seconds

Link to post
Share on other sites
Posted · Original PosterOP
On 6/12/2020 at 10:43 AM, MonkeyPants said:

I've only heard good things about Google TensorFlow.
It has an easy API and is probably the most trained model.

Yes me to. Haven't figured out what is exactly out what it is but as said above I already have a face detection and id programs. Thanks for the tip!

Link to post
Share on other sites
Posted · Original PosterOP
On 6/14/2020 at 2:17 PM, Mardax007 said:

Thanks for the face detection code but it already had that. I was looking for a face recognition program with deep learning. And I found it yesterday. But there is one problem:


# python recognize_faces_image.py --encodings encodings.pickle --image examples/example_01.png 

# import the necessary packages
import face_recognition
import argparse
import pickle
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-e", "--encodings", required=True,
	help="path to serialized db of facial encodings")
ap.add_argument("-i", "--image", required=True,
	help="path to input image")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
	help="face detection model to use: either `hog` or `cnn`")
args = vars(ap.parse_args())

# load the known faces and embeddings
print("[INFO] loading encodings...")
data = pickle.loads(open(args["encodings"], "rb").read())

# load the input image and convert it from BGR to RGB
image = cv2.imread(args["image"])
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# detect the (x, y)-coordinates of the bounding boxes corresponding
# to each face in the input image, then compute the facial embeddings
# for each face
print("[INFO] recognizing faces...")
boxes = face_recognition.face_locations(rgb,
	model=args["detection_method"])
encodings = face_recognition.face_encodings(rgb, boxes)

# initialize the list of names for each face detected
names = []

# loop over the facial embeddings
for encoding in encodings:
	# attempt to match each face in the input image to our known
	# encodings
	matches = face_recognition.compare_faces(data["encodings"],
		encoding)
	name = "Unknown"

	# check to see if we have found a match
	if True in matches:
		# find the indexes of all matched faces then initialize a
		# dictionary to count the total number of times each face
		# was matched
		matchedIdxs = [i for (i, b) in enumerate(matches) if b]
		counts = {}

		# loop over the matched indexes and maintain a count for
		# each recognized face face
		for i in matchedIdxs:
			name = data["names"][i]
			counts[name] = counts.get(name, 0) + 1

		# determine the recognized face with the largest number of
		# votes (note: in the event of an unlikely tie Python will
		# select first entry in the dictionary)
		name = max(counts, key=counts.get)
	
	# update the list of names
	names.append(name)

# loop over the recognized faces
for ((top, right, bottom, left), name) in zip(boxes, names):
	# draw the predicted face name on the image
	cv2.rectangle(image, (left, top), (right, bottom), (0, 255, 0), 2)
	y = top - 15 if top - 15 > 15 else top + 15
	cv2.putText(image, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,
		0.75, (0, 255, 0), 2)

# show the output image
cv2.imshow("Image", image)
cv2.waitKey(0)

Line 32 where boxes is defined takes 28 seconds to define and that's way to long. Is there any way to define it outside the function or make the process faster?

My and goal is this: The camera sees a face( an other program), it calls the id function, the id function takes a picture and quickly1 ids the person. (There is more but that's irrelevant)

 

1.quickly = 2 to 10 seconds

 

Link to post
Share on other sites
Posted · Original PosterOP

I have done it. I needed to set the methode to HoG is stead of CNN. Now it is blazing fast! Full code coming soon.

Link to post
Share on other sites
Posted · Original PosterOP

Doing some training. HoG is has really fast training. Going thru 6200 photo's in 30 minutes. Before it was 7 hours! 🥳

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×