OpenCV 4.2 with GPU support compile errors and remedies (SOLVED)

Discussion topics related to mobile applications and ZoneMinder Event Server (including machine learning)
Post Reply
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

OpenCV 4.2 with GPU support compile errors and remedies (SOLVED)

Post by tsp84 »

SEE LAST POST FOR SOLUTION/EXPLANATION


When i manually run

Code: Select all

sudo -u www-data /var/lib/zmeventnotification/bin/zm_event_start.sh <one of my eid> <monitor id>
it runs for a few seconds and then returns nothing.
If I run

Code: Select all

sudo -u www-data /var/lib/zmeventnotification/bin/zm_event_start.sh <one of my eid>
it errors out with...

Code: Select all

usage: zm_detect.py [-h] [-c CONFIG] [-e EVENTID] [-p EVENTPATH]
                    [-m MONITORID] [-v] [-o OUTPUT_PATH] [-f FILE] [-r REASON]
                    [-n] [-d]
zm_detect.py: error: argument -m/--monitorid: expected one argument
Am I missing something? shouldnt it return something or does that mean it found nothing at all? The eid i'm feeding it has a person walking up to my doorway from the front street then walking away, roughly a 1 minute clip. So it should find a vehicle and person no problem. Is there a different test script available to make sure open cv is working properly with my gpu? (1660 ti)
Last edited by tsp84 on Mon Jan 04, 2021 10:51 pm, edited 3 times in total.
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: machine learning help, already compiled opencv with gpu support and imported.

Post by tsp84 »

Reading the logs it detects a car but then crashes due to face recognition not being installed. I installed face recognition and now get a different error. it finds the car though! Im almost there!

error from face recognition not being installed.

Code: Select all

01/03/21 20:47:08 zmesdetect_m5[16001] INF zm_detect.py:205 [---------| pyzm version:0.3.17, hook version:6.0.6,  ES version:6.0.6 , OpenCV version:4.2.0|------------]
01/03/21 20:47:08 zmesdetect_m5[16001] INF zm_detect.py:231 [Importing local classes for Object/Face]
01/03/21 20:47:17 zmesdetect_m5[16001] INF zm_detect.py:636 [labels found: ['car']]
01/03/21 20:47:18 zmesdetect_m5[16001] ERR zm_detect.py:339 [Error importing face recognition. Make sure you did sudo -H pip3 install face_recognition]
01/03/21 20:47:18 zmesdetect_m5[16001] FAT zm_detect.py:861 [Unrecoverable error:No module named 'face_recognition' Traceback:Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 858, in <module>
    main_handler()
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 337, in main_handler
    import pyzm.ml.face as face
  File "/usr/local/lib/python3.8/dist-packages/pyzm/ml/face.py", line 3, in <module>
    import pyzm.ml.face_train as train
  File "/usr/local/lib/python3.8/dist-packages/pyzm/ml/face_train.py", line 11, in <module>
    import face_recognition
ModuleNotFoundError: No module named 'face_recognition'
]
Error after face recognition installed

Code: Select all

01/03/21 21:34:13 zmesdetect_m5[18738] INF zm_detect.py:205 [---------| pyzm version:0.3.17, hook version:6.0.6,  ES version:6.0.6 , OpenCV version:4.2.0|------------]
01/03/21 21:34:13 zmesdetect_m5[18738] INF zm_detect.py:231 [Importing local classes for Object/Face]
01/03/21 21:34:22 zmesdetect_m5[18738] INF zm_detect.py:636 [labels found: ['car']]
01/03/21 21:34:26 zmesdetect_m5[18738] FAT zm_detect.py:861 [Unrecoverable error:int() can't convert non-string with explicit base Traceback:Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 858, in <module>
    main_handler()
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 344, in main_handler
    m = face.Face(logger=g.logger, options=g.config, upsample_times=g.config['face_upsample_times'],
  File "/usr/local/lib/python3.8/dist-packages/pyzm/ml/face.py", line 92, in __init__
    train.FaceTrain(options=self.options).train()
  File "/usr/local/lib/python3.8/dist-packages/pyzm/ml/face_train.py", line 35, in train
    num_jitters = int(self.options.get('face_num_jitters'),0)
TypeError: int() can't convert non-string with explicit base
]
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: machine learning help, already compiled opencv with gpu support and imported.

Post by tsp84 »

Removing face from the .ini gets me a result now. I will go back and see the facial recognition dependancies install section, must of missed something.

Edit: No, I have everything installed for face recognition, any ideas on the error?
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: machine learning help, already compiled opencv with gpu support and imported.

Post by tsp84 »

Alright, so after some testing/debugging this is what I found out. I had to compile opencv with GPU support and I ended up using the wrong ARCH; I used 6.1 when it should be 7.x for a 1660 ti. However, the object detection worked for me but not facial, I saw another post with same errors and the remedy seemed to be upgrading so pyzm was over 0.3.19. After upgrading ES and hooks etc. I got the 'make_policy' ERROR when running object, face, alpr.

I recompiled opencv 4.2 with 7.5 as ARCH and now I get no errors. As a side note can I upgrade to opencv 4.3 and keep using GPU for yolo v4?

Also a weird quirk for when I compiled opencv 4.2. I am using ubuntu 20 lxc which has gcc-9 as default. I can compile the first 13% with gcc-9 until error then need to use gcc-6 to compile remainder of opencv. If I try and compile from scratch with gcc-6 it errors out at 11%. So gcc-9 for first 13% until it errors and says use gcc-7 or under, then use gcc-6 to completion.

So after you get an error at 13% of your make using gcc 9

Code: Select all

#Add this repo to /etc/apt/source.list -> deb http://archive.ubuntu.com/ubuntu bionic main universe
sudo apt update
sudo apt install gcc-6 g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 1
gcc --version

Make sure it returns version 6.x and rerun your make to continue compiling. After completion you can purge gcc-6 and link gcc-9 to gcc

Code: Select all

sudo apt purge gcc-6
sudo apt autoremove --purge
sudo ln -sf /usr/bin/gcc-9 /usr/bin/gcc
gcc --version 			# make sure it returns 9.x
#Remove the repo from /etc/apt/source.list
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: OpenCV 4.2 with GPU support compile errors and remedies (SOLVED)

Post by Magic919 »

I dont have GPU in my server, but I'm on 4.5 and use ZMES. My Ubuntu server on gcc 9 builds it ok.

I presume you've encountered this site on your journey - https://www.pyimagesearch.com/2020/02/0 ... and-cudnn/
-
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: OpenCV 4.2 with GPU support compile errors and remedies (SOLVED)

Post by tsp84 »

Yes I used that site to compile 4.2 with CUDA. I'm going to try 4.4.0 tonight and see if I can use yolo v4.

A sidenote is when I was running the 0.3.17 pyzm with ES and yolov3 it seems like the person detection was better. This is my first time doing anything with ml so I have to read up and see if I can train ES to detect certain things.

Zmninja and es server are amazing. Donating today to zm and zmninja.
Post Reply