Mezbaldwin
Posts: 7
Joined: Tue Mar 22, 2022 8:00 pm

Face Recognition

Sat Jul 16, 2022 1:24 pm

Hello All,

I have been struggling on this for some time now. Im following theses instructions (https://www.tomshardware.com/how-to/ras ... ecognition) All installs correctly until I get to Part 2 line 14.

I open a new terminal and input the following (As in attached image) and get an error message about import face_recognition. In the instruction it says if you have this error do the following If, when training your model (Part 2, step 15), you get errors saying “No module named imutils” or “No module named face-recognition,” install these again using pip2 instead of pip.

This is the python from the train_model.py file (https://github.com/Mezbaldwin/Raspberry ... n_model.py)

I have done the install with pip2 and still get the same error.

Has anyone done this project before if so could I please get some help and advice.
Attachments
Terminal.jpg
Terminal.jpg (23.41 KiB) Viewed 1188 times

gordon77
Posts: 7052
Joined: Sun Aug 05, 2012 3:12 pm

Re: Face Recognition

Sat Jul 16, 2022 1:58 pm

It has a - not a _ ?

pip install face-recognition

Mezbaldwin
Posts: 7
Joined: Tue Mar 22, 2022 8:00 pm

Re: Face Recognition

Sun Jul 17, 2022 8:07 am

Thank you, I'm a little confused on what you mean. Sorry.

I have put it in both ways with - and _

Is this what you mean?

gordon77
Posts: 7052
Joined: Sun Aug 05, 2012 3:12 pm

Re: Face Recognition

Sun Jul 17, 2022 8:33 am

When l read the installation instructions you used l noticed it said what is shown below, which has a -, but when you import it it uses a _. This could be a typo.

Did it install correctly ?
Attachments
IMG_20220717_093100.jpg
IMG_20220717_093100.jpg (24.02 KiB) Viewed 1101 times

Mezbaldwin
Posts: 7
Joined: Tue Mar 22, 2022 8:00 pm

Re: Face Recognition

Sun Jul 17, 2022 8:58 am

Its still not installing correctly, the below what's I've done.

In the train_model.py file I have just changed the import to import face-recognition (show below)

Code: Select all

#! /usr/bin/python

# import the necessary packages
from imutils import paths
import face-recognition
#import argparse
import pickle
import cv2
import os

# our images are located in the dataset folder
print("[INFO] start processing faces...")
imagePaths = list(paths.list_images("dataset"))

# initialize the list of known encodings and known names
knownEncodings = []
knownNames = []

# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
	# extract the person name from the image path
	print("[INFO] processing image {}/{}".format(i + 1,
		len(imagePaths)))
	name = imagePath.split(os.path.sep)[-2]

	# load the input image and convert it from RGB (OpenCV ordering)
	# to dlib ordering (RGB)
	image = cv2.imread(imagePath)
	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,
		model="hog")

	# compute the facial embedding for the face
	encodings = face_recognition.face_encodings(rgb, boxes)

	# loop over the encodings
	for encoding in encodings:
		# add each encoding + name to our set of known names and
		# encodings
		knownEncodings.append(encoding)
		knownNames.append(name)

# dump the facial encodings + names to disk
print("[INFO] serializing encodings...")
data = {"encodings": knownEncodings, "names": knownNames}
f = open("encodings.pickle", "wb")
f.write(pickle.dumps(data))
f.close()
and still get this error (Show Below)

Code: Select all

  File "train_model.py", line 5
    import face-recognition
               ^
SyntaxError: invalid syntax
I have changed it back to import face_recognition and get the below error still.

Code: Select all

Traceback (most recent call last):
  File "train_model.py", line 5, in <module>
    import face_recognition
ImportError: No module named face_recognition

Im I being stupid?

gordon77
Posts: 7052
Joined: Sun Aug 05, 2012 3:12 pm

Re: Face Recognition

Sun Jul 17, 2022 9:36 am

Have you tried pip install face_recognition ?

Mezbaldwin
Posts: 7
Joined: Tue Mar 22, 2022 8:00 pm

Re: Face Recognition

Sun Jul 17, 2022 11:47 am

Yes and still the same result. Im doing this on Debian Buster OS

Code: Select all

pi@raspberrypi:~ $ pip install face_recognition
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting face_recognition
  Using cached https://files.pythonhosted.org/packages/1e/95/f6c9330f54ab07bfa032bf3715c12455a381083125d8880c43cbe76bb3d0/face_recognition-1.3.0-py2.py3-none-any.whl
Collecting dlib>=19.7 (from face_recognition)
  Using cached https://files.pythonhosted.org/packages/e5/3b/7a8522a5c2ef6ff6252e46b0788b3d2c2280198c49d6ecf3b576b171045f/dlib-19.24.0.tar.gz
Collecting face-recognition-models>=0.3.0 (from face_recognition)
  Downloading https://www.piwheels.org/simple/face-recognition-models/face_recognition_models-0.3.0-py2.py3-none-any.whl (100.6MB)
    99% |████████████████████████████████| 100.6MB 6.7MB/s eta 0:00:01Killed
pi@raspberrypi:~ $ 

Code: Select all

pi@raspberrypi:~ $ cd facial_recognition
pi@raspberrypi:~/facial_recognition $ python train_model.py
Traceback (most recent call last):
  File "train_model.py", line 5, in <module>
    import face_recognition
ImportError: No module named face_recognition
pi@raspberrypi:~/facial_recognition $ 

gordon77
Posts: 7052
Joined: Sun Aug 05, 2012 3:12 pm

Re: Face Recognition

Sun Jul 17, 2022 12:38 pm

If using python3 try pip3 install face_recognition

Mezbaldwin
Posts: 7
Joined: Tue Mar 22, 2022 8:00 pm

Re: Face Recognition

Sun Jul 17, 2022 12:51 pm

Done that too, should I try it with face-recognition

Code: Select all

pi@raspberrypi:~ $ pip3 install face_recognition
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting face_recognition
  Using cached https://files.pythonhosted.org/packages/1e/95/f6c9330f54ab07bfa032bf3715c12455a381083125d8880c43cbe76bb3d0/face_recognition-1.3.0-py2.py3-none-any.whl
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from face_recognition) (1.16.2)
Collecting face-recognition-models>=0.3.0 (from face_recognition)
  Downloading https://www.piwheels.org/simple/face-recognition-models/face_recognition_models-0.3.0-py2.py3-none-any.whl (100.6MB)
    100% |████████████████████████████████| 100.6MB 4.2kB/s 
Requirement already satisfied: Click>=6.0 in /usr/lib/python3/dist-packages (from face_recognition) (7.0)
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (from face_recognition) (5.4.1)
Collecting dlib>=19.7 (from face_recognition)
  Downloading https://www.piwheels.org/simple/dlib/dlib-19.24.0-cp37-cp37m-linux_armv7l.whl (3.2MB)
    100% |████████████████████████████████| 3.2MB 127kB/s 
Installing collected packages: face-recognition-models, dlib, face-recognition
Successfully installed dlib-19.24.0 face-recognition-1.3.0 face-recognition-models-0.3.0

gordon77
Posts: 7052
Joined: Sun Aug 05, 2012 3:12 pm

Re: Face Recognition

Sun Jul 17, 2022 12:54 pm

Did it work ?

Mezbaldwin
Posts: 7
Joined: Tue Mar 22, 2022 8:00 pm

Re: Face Recognition

Sun Jul 17, 2022 1:12 pm

Nope, I've rebooted and no changes. Do you know any other face recognition for pi4?

gordon77
Posts: 7052
Joined: Sun Aug 05, 2012 3:12 pm

Re: Face Recognition

Sun Jul 17, 2022 4:10 pm

Have you tried python3 train_model.py ?

Mezbaldwin
Posts: 7
Joined: Tue Mar 22, 2022 8:00 pm

Re: Face Recognition

Thu Jul 21, 2022 2:41 pm

Still not working. im going to have a look at some different instruction.

Rit789
Posts: 1
Joined: Mon Dec 05, 2022 2:16 am

Re: Face Recognition

Mon Dec 05, 2022 2:20 am

Facing the same problem, have you fixed it by any chance?

Return to “Other projects”