object_detection_pattern with old ZMES and new MLAPI for specific monitors

Discussion topics related to mobile applications and ZoneMinder Event Server (including machine learning)
Post Reply
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

object_detection_pattern with old ZMES and new MLAPI for specific monitors

Post by ranger21 »

Hello!
I can't seem to have object_detection_pattern to work for specific monitors with mlapi

MLAPI.log

Code: Select all

Oct 31 2021 20:12:40.938412 [DBG 2] Found monitor specific section for monitor: 13
Oct 31 2021 20:12:40.938434 [DBG 2] stream sequence not found in globals
Oct 31 2021 20:12:40.938459 [DBG 2] match_past_detections is not a polygon, adding it as unknown string key
Oct 31 2021 20:12:40.938477 [DBG 2] [monitor-13] overrides key:object_detection_pattern with value:(person|bicycle|cat|dog)
Oct 31 2021 20:12:40.938496 [DBG 2] [monitor-13] overrides key:wait with value:1
mlapiconfig.ini monitor specific setting

Code: Select all

[monitor-13]
match_past_detections=yes
object_detection_pattern=(person|bicycle|cat|dog)
wait=1
objectconfig.ini

Code: Select all

[monitor-13]
object_detection_pattern=(person|cat|dog)
match_past_detections=yes
detection_seq=object
wait=1
objectconfig.ini global pattern
object_detection_pattern=(person|car|motorbike|bus|truck|boat|cat|dog|bicycle)

mlapiconfig.ini global pattern
object_detection_pattern=(person|car|motorbike|bus|truck|boat|bicycle|cat|dog)


So... mlapi completely ignores monitor specific settings from both ini's and uses global pattern, what could be wrong? In logs on start it says that loaded pattern.

python mlapi.py --version
2.2.23

objectconfig.ini version 1.2 (dunno how to get version of ZMES, but i have zoneminder 1.34)
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: object_detection_pattern with old ZMES and new MLAPI for specific monitors

Post by tsp84 »

Is "object_detection_pattern" defined inside of your ml_sequence as a substitution variable for the object-> general-> pattern key?


Sanitize and post a gist or Pastebin of your config files.

Code: Select all

/var/lib/zmeventnotification/bin/zm_detect.py --version
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

Re: object_detection_pattern with old ZMES and new MLAPI for specific monitors

Post by ranger21 »

Yep, i do have it defined both in mlapi and objectconfig
'general':{
'pattern':'{{object_detection_pattern}}',

/var/lib/zmeventnotification/bin/zm_detect.py --version
hooks:6.1.5 pyzm:0.3.25

objectconfig.ini
https://pastebin.com/6AYZyuiP

mlapiconfig.ini
https://pastebin.com/epbL4WYG
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: object_detection_pattern with old ZMES and new MLAPI for specific monitors

Post by tsp84 »

If I remember correctly I had issues with things like this with the original software but I can't recall the exact fix.

I'll take a look at your config and the original source code to see if I can pinpoint any issues.


Also please post the full debug output of the event. The logs may have some clues as to what's going on.
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: object_detection_pattern with old ZMES and new MLAPI for specific monitors

Post by tsp84 »

Config looks good so I am assuming its something else going on, if you can sanitize and post the logs for that event it might have some clues as to whats going on. Ill look at original source to see if there's something going on there.
tsp84
Posts: 227
Joined: Thu Dec 24, 2020 4:04 am

Re: object_detection_pattern with old ZMES and new MLAPI for specific monitors

Post by tsp84 »

I think I remember what's going on, since it is not a key that is in the defaults in common_params.py of zmes hook helpers, when it comes across it in the per-monitor overrides it just skips it.

I can't remember for certain but I rewrote all of that logic to make things work as expected. Maybe I just don't understand how to configure it correctly with the original repo. I can't really help you much more as I don't use the original repos.

If I were you I would try putting some print statements in the source files right before ZMES sends the detection request to mlapi to check what ml_options and stream_options (line 145 of zm_detect.py) contain and on the mlapi side when it gets the detection to print out the ml_sequence and stream_sequence before it sends it off to the m.detect_stream() method (line 225 of mlapi.py).

You could also try adding it to the default config in common_params.py of the zmes helpers source files (/usr/lib/python3.9/dist-packages/zmes-hook-helpers/common_params.py I think?).

Just follow the structure laid out already. If anything goes wrong just redownload and reinstall the original repos.

Examples ->

Code: Select all

(zm_detect.py)
print(f"\n\n{ml_options = }\n\n")
print(f"{stream_options = }\n\n")


(mlapi.py)
print(f"\n\n{ml_options = }\n\n")
print(f"{stream_options}\n\n")


(common_params.py adding the object_detection_pattern key as a known valid key)

config_vals = {
    'version':{
            'section': 'general',
            'default': None,
            'type': 'string',
        },
      'object_detection_pattern':{
            'section': 'general',
            'default': '(person|unicorn)',
            'type': 'string',
        },


# If I remember correctly once you have that key in the common_params.py it is now a key you can override per monitor in your config
ranger21
Posts: 16
Joined: Fri Dec 04, 2020 4:55 am

Re: object_detection_pattern with old ZMES and new MLAPI for specific monitors

Post by ranger21 »

Thanks, i'll look into it. Well, for my use case really just works
'ignore_past_detection_labels': ['person']
in general section

Since humans mostly only objects i've always want to catch and that doesn't really depend on monitor, so match_past_detections=yes only matter for other objects. I do delete events without objects in them.

and wide global object detection pattern just works fine then for my use case
Post Reply