zmeventnotification on Pi4

Discussion topics related to mobile applications and ZoneMinder Event Server (including machine learning)
Post Reply
Chimaera
Posts: 21
Joined: Mon Apr 15, 2019 8:13 pm

zmeventnotification on Pi4

Post by Chimaera »

I have a new Pi4 running Buster and after a LOT of effort last night managed to get zmeventnotification working. However for some reason I can't get it to use "tiny" as the yolo_type, it will default back to yolo. This is (of course) very slow on even a Pi4, a single 640x480 image is taking 50+ seconds. In my objectconfig.ini I have :

Code: Select all

yolo_type=tiny
models=yolo
detection_mode=first
and when I run detect.py my syslog shows :

Code: Select all

Jul 13 08:32:43 localhost detect:[2160][monitor_m12]: DEBUG [No polygon area specfied, so adding a full image polygon:[{'name': 'full_image', 'value': [(0, 0), (640, 0), (640, 480), (0, 480)]}]]
Jul 13 08:32:43 localhost detect:[2160][monitor_m12]: DEBUG [User ALPR if vehicle found: False]
Jul 13 08:32:43 localhost detect:[2160][monitor_m12]: DEBUG [|--> model:yolo init took: 5.3e-05s]
Jul 13 08:32:43 localhost detect:[2160][monitor_m12]: DEBUG [Using model: yolo with /var/lib/zmeventnotification/images/46447-alarm.jpg]
Jul 13 08:32:44 localhost detect:[2160][monitor_m12]: DEBUG [Initializing Yolo]
Jul 13 08:32:44 localhost detect:[2160][monitor_m12]: DEBUG [config:/var/lib/zmeventnotification/models/yolov3/yolov3.cfg, weights:/var/lib/zmeventnotification/models/yolov3/yolov3.weights]
Any idea why detect.py isn't picking up my choice of tiny?
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmeventnotification on Pi4

Post by asker »

I just tried it and it had no problem using tiny.

1. Make sure you are on the latest ES and hooks (the logs you posted don't show the version). Note that ES and hooks have different version #s
2. Make sure you are using the right config file
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Chimaera
Posts: 21
Joined: Mon Apr 15, 2019 8:13 pm

Re: zmeventnotification on Pi4

Post by Chimaera »

I followed your instructions, cloning the latest GIT so it should be the latest versions of each. Which config do you mean when you say "the right config file"? /etc/zm/objectconfig.ini is the file that controls detect.py, right?
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmeventnotification on Pi4

Post by asker »

Yes, /etc/zm/objectconfig.ini
Try running it from command line (not as a daemon) and see what it picks up
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Chimaera
Posts: 21
Joined: Mon Apr 15, 2019 8:13 pm

Re: zmeventnotification on Pi4

Post by Chimaera »

I'm rebuilding my install from scratch and trying again because I tried so many things to get OpenCV to run I probably messed something up. What version of OpenCV are you running on Buster/Pi4 and how did you install? Did you build from source or is there a whl somewhere for Python 3.7 that I'm missing??
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmeventnotification on Pi4

Post by asker »

I don't use Pi4/Buster.
I am on ubuntu

I built everything from source because I use the GPU. As long as you are on Python 3 & OpenCV 4.1.x, its all good (there are packages available - not sure about buster, don't have to build from source)
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Chimaera
Posts: 21
Joined: Mon Apr 15, 2019 8:13 pm

Re: zmeventnotification on Pi4

Post by Chimaera »

Yeah I've been struggling to find a package for opencv cp37 on Armv7 which is why I was building.
Chimaera
Posts: 21
Joined: Mon Apr 15, 2019 8:13 pm

Re: zmeventnotification on Pi4

Post by Chimaera »

ok I'm at a loss, it still won't use tiny. If I manually edit yolo.py and force it to run tiny_weights it works fine.

I'm running this command :

Code: Select all

sudo -u www-data /usr/bin/detect.py -c /etc/zm/objectconfig.ini -e 46495 -m 16
This is the objectconfig.ini file :

Code: Select all

# Configuration file for object detection

# NOTE: ALL parameters here can be overriden
# on a per monitor basis if you want. Just
# duplicate it inside the correct [monitor-<num>] section

[general]
portal=https://*****/zm
user=*****
password=*****
allow_self_signed=yes
#yolo_type=full
yolo_type=tiny

# if yes, last detection will be stored for monitors
# and bounding boxes that match, along with labels
# will be discarded for new detections. This may be helpful
# in getting rid of static objects that get detected
# due to some motion.
#match_past_detections=yes
match_past_detections=no

# sequence of models to run for detection
models=yolo
# if all, then we will loop through all models
# if first then the first success will break out
detection_mode=first

# If you need basic auth to access ZM
#basic_user=user
#basic_password=password

# path to store downloaded images
# needs to be RW www-data/apache
image_path=/var/lib/zmeventnotification/images

# this is the global detection pattern used for all monitors.
# choose any set of classes from here https://github.com/pjreddie/darknet/blob/master/data/coco.names
# for everything, make it .*
#detect_pattern=(person|car|motorbike|bus|truck|boat)
detect_pattern=.*

# global settings for
# bestmatch, alarm, snapshot OR a specific frame ID
frame_id=bestmatch

# this is the to resize the image before analysis is done
resize=1200
# set to yes, if you want to remove images after analysis
# setting to yes is recommended to avoid filling up space
# keep to no while debugging/inspecting masks
# Note this does NOT delete debug images later
delete_after_analyze=no

# If yes, will write an image called <filename>-bbox.jpg as well
# which contains the bounding boxes. This has NO relation to
# write_image_to_zm
# Typically, if you enable delete_after_analyze you may
# also want to set  write_debug_image to no.
write_debug_image=no

# if yes, will write an image with bounding boxes
# this needs to be yes to be able to write a bounding box
# image to ZoneMinder that is visible from its console
write_image_to_zm=yes

# Adds percentage to detections
# hog/face shows 100% always
show_percent=yes

# log level can be info,error,debug
log_level=debug

# color to be used to draw the polygons you specified
poly_color=(255,255,255)
import_zm_zones=no


## Monitor specific settings
#
# - Format:  [monitor-<mid>]
#
# Parameters:
# polygon areas where object detection will be done.
# You can name them anything except the keywords defined in the optional
# params below. You can put as many polygons as you want per [monitor-<mid>]
# (see examples).
#
# detect_pattern: overrides the detection patterns used for this monitor.
#
# Examples:

# config files for yolo
[yolo]
config=/var/lib/zmeventnotification/models/yolov3/yolov3.cfg
weights=/var/lib/zmeventnotification/models/yolov3/yolov3.weights
labels=/var/lib/zmeventnotification/models/yolov3/yolov3_classes.txt

tiny_config=/var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.cfg
tiny_weights=/var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.weights
tiny_labels=/var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.txt

# config params for HOG
[hog]
stride=(4,4)
padding=(8,8)
scale=1.05
mean_shift=-1

[face]
known_images_path=/var/lib/zmeventnotification/known_faces

# read https://github.com/ageitgey/face_recognition/wiki/Face-Recognition-Accuracy-Problems
# read https://github.com/ageitgey/face_recognition#automatically-find-all-the-faces-in-an-image
# and play around

# quick overview:
# num_jitters is how many times to distort images
# upsample_times is how many times to upsample input images (for small faces, for example)
# model can be hog or cnn. cnn may be more accurate, but I haven't found it to be

face_num_jitters=1
face_model=hog
face_upsample_times=1

[alpr]

alpr_use_after_detection_only=yes

# -----| If you are using plate recognizer | ------
#alpr_service=plate_recognizer
# If you want to host a local SDK https://app.platerecognizer.com/sdk/
#alpr_url=https://localhost:8080
# Plate recog replace with your api key
#alpr_key=__PLATERECOG_KEY__
# if yes, then it will log usage statistics of the ALPR service
platerec_stats=no
# If you want to specify regions. See http://docs.platerecognizer.com/#regions-supported
#platerec_regions=['us','cn','kr']
# minimal confidence for actually detecting a plate
platerec_min_dscore=0.1
# minimal confidence for the translated text
platerec_min_score=0.2


# ----| If you are using openALPR |-----
alpr_service=open_alpr
alpr_key=__OPENALPR_SECRET__

# For an explanation of params, see http://doc.openalpr.com/api/?api=cloudapi
openalpr_recognize_vehicle=1
#openalpr_country=us
#openalpr_state=ca
# openalpr returns percents, but we convert to between 0 and 1
openalpr_min_confidence=0.3
This is the entry in syslog that corresponds :

Code: Select all

Jul 14 14:50:48 localhost detect:[5313][monitor_m16]: INFO [---------| app version: 3.3.5 |------------]
Jul 14 14:50:48 localhost detect:[5313][monitor_m16]: INFO [Log level set to:debug]
Jul 14 14:50:48 localhost detect:[5313][monitor_m16]: DEBUG [allowing self-signed certs to work...]
Jul 14 14:50:48 localhost detect:[5313][monitor_m16]: DEBUG [Trying to download https:/****/zm/index.php?view=image&eid=46495&fid=alarm&username=**&password=*****]
Jul 14 14:50:48 localhost detect:[5313][monitor_m16]: DEBUG [Trying to download https://****/zm/index.php?view=image&eid=46495&fid=snapshot&username=**&password=*****]
Jul 14 14:50:49 localhost detect:[5313][monitor_m16]: DEBUG [No polygon area specfied, so adding a full image polygon:[{'name': 'full_image', 'value': [(0, 0), (640, 0), (640, 480), (0, 480)]}]]
Jul 14 14:50:49 localhost detect:[5313][monitor_m16]: DEBUG [resizing to 1200 before analysis...]
Jul 14 14:50:49 localhost detect:[5313][monitor_m16]: DEBUG [resized polygons x=1.0/y=1.0: [{'name': 'full_image', 'value': [(0, 0), (640, 0), (640, 480), (0, 480)]}]]
Jul 14 14:50:49 localhost detect:[5313][monitor_m16]: DEBUG [User ALPR if vehicle found: False]
Jul 14 14:50:49 localhost detect:[5313][monitor_m16]: DEBUG [|--> model:yolo init took: 0.000175s]
Jul 14 14:50:49 localhost detect:[5313][monitor_m16]: DEBUG [Using model: yolo with /var/lib/zmeventnotification/images/46495-alarm.jpg]
Jul 14 14:50:50 localhost detect:[5313][monitor_m16]: DEBUG [Initializing Yolo]
Jul 14 14:50:50 localhost detect:[5313][monitor_m16]: DEBUG [config:/var/lib/zmeventnotification/models/yolov3/yolov3.cfg, weights:/var/lib/zmeventnotification/models/yolov3/yolov3.weights]
Jul 14 14:51:17 localhost detect:[5313][monitor_m16]: DEBUG [|--> model:yolo detection took: 27.736631s]
Jul 14 14:51:17 localhost detect:[5313][monitor_m16]: DEBUG [ALPR not in use, no need for look aheads in processing]
Jul 14 14:51:17 localhost detect:[5313][monitor_m16]: DEBUG [No match found in /var/lib/zmeventnotification/images/46495-alarm.jpg using model:yolo]
Jul 14 14:51:17 localhost detect:[5313][monitor_m16]: DEBUG [Using model: yolo with /var/lib/zmeventnotification/images/46495-snapshot.jpg]
Jul 14 14:51:43 localhost detect:[5313][monitor_m16]: DEBUG [|--> model:yolo detection took: 26.390611s]
Jul 14 14:51:43 localhost detect:[5313][monitor_m16]: DEBUG [ALPR not in use, no need for look aheads in processing]
Jul 14 14:51:43 localhost detect:[5313][monitor_m16]: DEBUG [No match found in /var/lib/zmeventnotification/images/46495-snapshot.jpg using model:yolo]
Jul 14 14:51:43 localhost detect:[5313][monitor_m16]: DEBUG [No patterns found using any models in all files]
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmeventnotification on Pi4

Post by asker »

I somehow get the feeling you are possibly using an older version of the hooks somewhere.

Lets do it cleanly, to make sure:

1. git clone https://github.com/pliablepixels/zmeventnotification
2. cd zmeventnotification
3. cp /etc/zm/objectconfig.ini mynewconfig.ini
4. Modify mynewconfig.ini to use tiny
5. Execute it _from_the_current_directory (important)

Code: Select all

sudo -u www-data ./detect.py -c ./mynewconfig.ini -e 46495 -m 16
The code that checks the model type is here, so you can even insert a simple

Code: Select all

print ('YOLO CONFIGURED IS {}'.format(g.config['yolo_type']))
before that
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Chimaera
Posts: 21
Joined: Mon Apr 15, 2019 8:13 pm

Re: zmeventnotification on Pi4

Post by Chimaera »

ok, I tried all that with the same results. I did some poking around in utils.py and uncommented the debug line (196) so that all of the config would be written to the syslog as it's being parsed. As you can see, "setting yolo_type to full" appears. I tested changing other settings like "resize" to an odd number just to make sure that it was 100% using the correct objectdetect.ini file and it is. Somewhere between kicking off detect.py and it getting to the process_config function it's losing that yolo_type variable.

EDIT : found it - you have yolo_type configured in common_params.py as being in the yolo section, but the objectdetect.ini has that variable at the top in the general section. Moving the variable into the yolo section fixes it.

Code: Select all

Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: INFO [---------| app version: 3.3.5 |------------]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: INFO [Log level set to:debug]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting portal to https://*****/zm]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting user to **]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting password to ***********]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting basic_user to ]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting basic_password to ***********]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting image_path to /var/lib/zmeventnotification/images]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting detect_pattern to (person|car|motorbike|bus|truck|boat)]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting match_past_detections to no]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting frame_id to bestmatch]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting wait to 0]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting resize to 1200]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting delete_after_analyze to yes]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting show_percent to no]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting log_level to debug]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting allow_self_signed to yes]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting write_image_to_zm to yes]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting write_debug_image to no]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting models to ['yolo']]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting detection_mode to all]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting import_zm_zones to no]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting poly_color to (255, 255, 255)]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting yolo_type to full]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting config to /var/lib/zmeventnotification/models/yolov3/yolov3.cfg]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting weights to /var/lib/zmeventnotification/models/yolov3/yolov3.weights]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting labels to /var/lib/zmeventnotification/models/yolov3/yolov3_classes.txt]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting tiny_config to /var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.cfg]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting tiny_weights to /var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.weights]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting tiny_labels to /var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.txt]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting stride to (4, 4)]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting padding to (8, 8)]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting scale to 1.05]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting mean_shift to -1]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting face_num_jitters to 1]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting face_upsample_times to 1]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting face_model to hog]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting known_images_path to /var/lib/zmeventnotification/known_faces]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting alpr_service to open_alpr]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting alpr_url to None]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting alpr_key to __OPENALPR_SECRET__]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting alpr_use_after_detection_only to yes]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting platerec_stats to no]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting platerec_regions to None]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting platerec_min_dscore to 0.1]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting platerec_min_score to 0.2]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting openalpr_recognize_vehicle to 1]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting openalpr_country to us]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting openalpr_state to None]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [Config: setting openalpr_min_confidence to 0.3]
Jul 14 19:21:01 localhost detect:[14937][monitor_m16]: DEBUG [allowing self-signed certs to work...]
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmeventnotification on Pi4

Post by asker »

Chimaera wrote: Sun Jul 14, 2019 11:29 pm EDIT : found it - you have yolo_type configured in common_params.py as being in the yolo section, but the objectdetect.ini has that variable at the top in the general section. Moving the variable into the yolo section fixes it.
Good catch! I over ride yolo_type on a per monitor basis, so I suppose that is why this did not affect me. Will put in a fix.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Post Reply