Page 1 of 1
[SOLVED] Problem with face recognition
Posted: Wed Apr 26, 2023 9:00 pm
by biologisch
After upgrade to ubuntu 22.04:
/etc/zm# sudo -u www-data /var/lib/zmeventnotification/bin/zm_train_faces.py 5
INF [zm_train_faces] [Setting up signal handler for logs]
INF [zm_train_faces] [Switching global logger to ZMLog]
INF [zm_train_faces] [Reading config from: /etc/zm/objectconfig.ini]
INF [zm_train_faces] [Reading secrets from: /etc/zm/secrets.ini]
INF [zm_train_faces] [Ignoring monitor specific settings, as you did not provide a monitor id]
04/26/23 22:56:06 zm_train_faces[35638] ERR face_train_dlib.py:128 [Error initializing face recognition: local variable 'person' referenced before assignment]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/pyzm/ml/face_train_dlib.py", line 118, in train
.format(person), len(face_locations))
UnboundLocalError: local variable 'person' referenced before assignment
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/lib/zmeventnotification/bin/zm_train_faces.py", line 33, in <module>
train.FaceTrain(options=g.config).train(size=args['size'])
File "/usr/local/lib/python3.10/dist-packages/pyzm/ml/face_train_dlib.py", line 129, in train
raise ValueError(
ValueError: Error opening known faces directory. Is the path correct?
Re: Problem with face recognition
Posted: Fri Apr 28, 2023 8:13 am
by Magic919
What does you known faces directory/content look like? That's what I'd check.
Re: Problem with face recognition
Posted: Sat Apr 29, 2023 10:03 pm
by biologisch
Only old pictures from the time before I upgrade to ubuntu 22.04

Re: Problem with face recognition
Posted: Sun Apr 30, 2023 6:33 am
by Magic919
Make sure it’s structured per the docs. If it’s just a folder of pictures, that’s not right.
Re: Problem with face recognition
Posted: Sun Jun 11, 2023 10:17 am
by biologisch
FIX!
After a while and some time for investigation I found the bug and here is the fix:
1. After a sudo -u www-data /var/lib/zmeventnotification/bin/zm_train_faces.py
Code: Select all
dtype=uint8), <_dlib_pybind11.full_object_detection object at 0x7fe95a72ce70>, 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/lib/zmeventnotification/bin/zm_train_faces.py", line 33, in <module>
train.FaceTrain(options=g.config).train(size=args['size'])
File "/usr/local/lib/python3.10/dist-packages/pyzm/ml/face_train_dlib.py", line 130, in train
raise ValueError(
ValueError: Error opening known faces directory. Is the path correct?
2. Modify this script here -> /usr/local/lib/python3.10/dist-packages/pyzm/ml/face_train_dlib.py
3. Go to line 80 and replace
Code: Select all
known_face = known_face[:, :, ::-1]
with
Code: Select all
known_face = cv2.cvtColor(known_face, cv2.COLOR_BGR2RGB)
4. Modify this script here -> /usr/local/lib/python3.10/dist-packages/pyzm/ml/face_dlib.py
5. Go to line 182 and replace
with
Code: Select all
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
Re: [SOLVED] Problem with face recognition
Posted: Sun Jun 11, 2023 5:36 pm
by iconnor
Fixes merged
Re: [SOLVED] Problem with face recognition
Posted: Wed Jun 14, 2023 2:02 am
by Meinta
Re: [SOLVED] Problem with face recognition
Posted: Sat Jun 24, 2023 6:31 pm
by GoDie
is this related?
Code: Select all
sudo -u www-data /var/lib/zmeventnotification/bin/zm_train_faces.py
INF [zm_train_faces] [Setting up signal handler for logs]
INF [zm_train_faces] [Switching global logger to ZMLog]
INF [zm_train_faces] [Reading config from: /etc/zm/objectconfig.ini]
INF [zm_train_faces] [Reading secrets from: /etc/zm/secrets.ini]
INF [zm_train_faces] [Ignoring monitor specific settings, as you did not provide a monitor id]
ERR [zm_train_faces] [Error initializing face recognition: module 'cv2' has no attribute 'COLOR_BG2RGB']
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/pyzm/ml/face_train_dlib.py", line 81, in train
known_face = cv2.cvtColor(known_face, cv2.COLOR_BG2RGB)
AttributeError: module 'cv2' has no attribute 'COLOR_BG2RGB'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/lib/zmeventnotification/bin/zm_train_faces.py", line 33, in <module>
train.FaceTrain(options=g.config).train(size=args['size'])
File "/usr/local/lib/python3.9/dist-packages/pyzm/ml/face_train_dlib.py", line 131, in train
raise ValueError(
ValueError: Error opening known faces directory. Is the path correct?
Re: [SOLVED] Problem with face recognition
Posted: Mon Jul 10, 2023 3:39 am
by fiatguy85
There may have been a typo on line 82 of face_train_dlib.py when the fixes were made. It should be cv2.COLOR_BGR2RGB.
Re: [SOLVED] Problem with face recognition
Posted: Mon Feb 05, 2024 1:54 am
by EK701
fiatguy85 wrote: ↑Mon Jul 10, 2023 3:39 am
There may have been a typo on line 82 of face_train_dlib.py when the fixes were made. It should be cv2.COLOR_BGR2RGB.
FYI, this is still an issue and fixing the typo solves it.
Re: [SOLVED] Problem with face recognition
Posted: Mon Feb 05, 2024 3:17 pm
by iconnor
Current version has the typo applied. Was committed on July 9th.
Re: [SOLVED] Problem with face recognition
Posted: Wed Feb 07, 2024 1:57 am
by EK701
iconnor wrote: ↑Mon Feb 05, 2024 3:17 pm
Current version has the typo applied. Was committed on July 9th.
Can you clarify what you mean by current version? I was running ZM 1.37.50 and had the typo. I just did an apt update and apt upgrade and it did update to a new sub-release of zm 1.37.50, but it made no changes to /usr/local/lib/python3.10/dist-packages/pyzm/ml/face_train_dlib.py
Am I missing something?
Thanks!
Re: [SOLVED] Problem with face recognition
Posted: Wed Feb 07, 2024 12:55 pm
by iconnor
pyzm is packages separately from zoneminder. I doubt apt will pick up the changes (perhaps we should package it for apt, I'll look into that). You need to updateit with pip. Or pip3 .
sudo pip3 install pyzm --upgrade
Should get you 0.3.64
Re: [SOLVED] Problem with face recognition
Posted: Wed Feb 07, 2024 4:09 pm
by EK701
iconnor wrote: ↑Wed Feb 07, 2024 12:55 pm
pyzm is packages separately from zoneminder. I doubt apt will pick up the changes (perhaps we should package it for apt, I'll look into that). You need to updateit with pip. Or pip3 .
sudo pip3 install pyzm --upgrade
Should get you 0.3.64
Thanks for the clarification!