ZoneMinder / zmeventnotification

Machine Learning powered Secure Websocket & MQTT based ZoneMinder event notification server
412 stars 128 forks source link

KeyError if only one model type in ml_sequence #354

Closed currand closed 3 years ago

currand commented 3 years ago

With ml_sequence as such:

ml_sequence= {
                'general': {
                        'model_sequence': 'object'
                },
                'object': {
                        'general':{
                                'pattern':'(person)',
                                'same_model_sequence_strategy': 'first' # also 'most', 'most_unique's
                        },
                        'sequence': [{
                                # YoloV4 on GPU if TPU fails (because sequence strategy is 'first')
                                'object_config':'{{base_data_path}}/models/yolov4/yolov4.cfg',
                                'object_weights':'{{base_data_path}}/models/yolov4/yolov4.weights',
                                'object_labels': '{{base_data_path}}/models/yolov4/coco.names',
                                'object_min_confidence': 0.3,
                                'object_framework':'opencv',
                                'object_processor': 'gpu'
                        }]
                }
        }

The following error is returned:

Zoneminder Version: 1.34.22

01/06/21 08:37:39 zmesdetect_m7[6666] INF ZMLog.py:212 [Setting up signal handler for logs]
01/06/21 08:37:40 zmesdetect_m7[6666] INF zm_detect.py:240 [---------| pyzm version:0.3.25, hook version:6.1.5,  ES version:6.1.5 , OpenCV version:4.5.0|------------]
01/06/21 08:37:41 zmesdetect_m7[6666] INF zm_detect.py:265 [Importing local classes for Object/Face]
01/06/21 08:37:42 zmesdetect_m7[6666] INF zm_detect.py:288 [Connecting with ZM APIs]
01/06/21 08:37:43 zmesdetect_m7[6666] FAT zm_detect.py:534 [Unrecoverable error:'object' Traceback:Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 531, in <module>
    main_handler()
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 379, in main_handler
    matched_data,all_data = m.detect_stream(stream=stream, options=stream_options)
  File "/usr/local/lib/python3.8/dist-packages/pyzm/ml/detect_sequence.py", line 521, in detect_stream
    for m in self.models[seq]:
KeyError: 'object'
]

Adding object to the model_sequence a second time resolves the issue

ml_sequence= {
                'general': {
                        'model_sequence': 'object,object'
                },

This appears to be caused by

        if manual_locking:
            for seq in self.model_sequence:
                for m in self.models[seq]:
                    m.release_lock()

Always being True if there is one model from this part of the code:

        if len(self.model_sequence) > 1:
            manual_locking = False
            self.logger.Debug(3,'Using automatic locking as we are switching between models')
        else:
            manual_locking = True
            self.logger.Debug(3,'Using manual locking as we are only using one model')
            for seq in self.model_sequence:
                self.ml_options[seq]['auto_lock'] = False
pliablepixels commented 3 years ago

I just ran with your exact ml_sequence and did not see an issue

pliablepixels commented 3 years ago

closing - no response