[SOLVED] Problem with face recognition

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
User avatar
biologisch
Posts: 96
Joined: Fri Aug 24, 2007 10:37 am

[SOLVED] Problem with face recognition

Post 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?
Last edited by biologisch on Sun Jun 11, 2023 10:18 am, edited 1 time in total.
ZM Versions = 1.36.33
zmeventnotification Version = "6.1.28"
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: Problem with face recognition

Post by Magic919 »

What does you known faces directory/content look like? That's what I'd check.
-
User avatar
biologisch
Posts: 96
Joined: Fri Aug 24, 2007 10:37 am

Re: Problem with face recognition

Post by biologisch »

Only old pictures from the time before I upgrade to ubuntu 22.04 :-(
ZM Versions = 1.36.33
zmeventnotification Version = "6.1.28"
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: Problem with face recognition

Post by Magic919 »

Make sure it’s structured per the docs. If it’s just a folder of pictures, that’s not right.
-
User avatar
biologisch
Posts: 96
Joined: Fri Aug 24, 2007 10:37 am

Re: Problem with face recognition

Post 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

Code: Select all

rgb_image = image[:, :, ::-1]
with

Code: Select all

rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
ZM Versions = 1.36.33
zmeventnotification Version = "6.1.28"
User avatar
iconnor
Posts: 3266
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: [SOLVED] Problem with face recognition

Post by iconnor »

Fixes merged
Meinta
Posts: 1
Joined: Wed Jun 14, 2023 1:37 am

Re: [SOLVED] Problem with face recognition

Post by Meinta »

oh. I got it Territorial io ;)
GoDie
Posts: 5
Joined: Sat Nov 14, 2020 2:37 pm

Re: [SOLVED] Problem with face recognition

Post 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?
fiatguy85
Posts: 6
Joined: Fri Jan 20, 2023 4:36 am

Re: [SOLVED] Problem with face recognition

Post 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.
EK701
Posts: 24
Joined: Thu Feb 06, 2020 4:26 pm

Re: [SOLVED] Problem with face recognition

Post 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.
User avatar
iconnor
Posts: 3266
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: [SOLVED] Problem with face recognition

Post by iconnor »

Current version has the typo applied. Was committed on July 9th.
EK701
Posts: 24
Joined: Thu Feb 06, 2020 4:26 pm

Re: [SOLVED] Problem with face recognition

Post 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!
User avatar
iconnor
Posts: 3266
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: [SOLVED] Problem with face recognition

Post 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
EK701
Posts: 24
Joined: Thu Feb 06, 2020 4:26 pm

Re: [SOLVED] Problem with face recognition

Post 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!
Post Reply