zmevennotification object detection on edge tpu

Discussion topics related to mobile applications and ZoneMinder Event Server (including machine learning)
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmevennotification object detection on edge tpu

Post by asker »

I don’t know. You are using someone’s docker image. You’ll have to ask them where they are storing it. I saw the dockerfile and it looks like they are just running it as is without debug logs. If so I doubt debug is stored anywhere but the docker author would know or fix their invocation so it’s stored. Run it manually with —debug.
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
VicThor
Posts: 39
Joined: Tue Oct 13, 2020 8:47 pm

Re: zmevennotification object detection on edge tpu

Post by VicThor »

Cheers, finally have it spewing:

Code: Select all

Jul 01 2021 12:41:56.718392 [DBG 1] Hashes are correct: password matched
Jul 01 2021 12:41:56.723684 [DBG 1] Monitor ID not specified, or not found in mlapi config, using zm_detect overrides
Jul 01 2021 12:41:56.723747 [DBG 2] using ml_sequence
Jul 01 2021 12:41:56.724581 [DBG 2] Found stream_sequence in mlapi config, ignoring objectconfig.ini
Jul 01 2021 12:41:56.724630 [DBG 1] Object Recognition requested
Jul 01 2021 12:41:56.724638 [DBG 1] Calling detect streams
Jul 01 2021 12:41:56.724651 [DBG 3] Using manual locking as we are only using one model
Jul 01 2021 12:41:56.724783 [DBG 2] Media get SSL certificate check has been disbled
Jul 01 2021 12:41:56.724838 [DBG 2] Using URL 34373 for stream
Jul 01 2021 12:41:56.724865 [DBG 2] We will only process frames: ['alarm', 'snapshot']
Jul 01 2021 12:41:56.724873 [DBG 2] No need to start streams, we are picking images from http://xxxxxxxxxxx/zm/index.php?view=image&eid=34373
Jul 01 2021 12:41:56.724895 [DBG 3] Reading http://xxxxxxxxxxx/zm/index.php?view=image&eid=34373&fid=alarm
Jul 01 2021 12:41:56.724924 [DBG 3] No need to relogin as access token still has 119.43901405 minutes remaining
Jul 01 2021 12:41:56.724944 [DBG 3] make_request called with url=http://xxxxxxxxxxx/zm/index.php?view=image&eid=34373&fid=alarm payload={} type=get query={'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJab25lTWluZGVyIiwiaWF0IjoxNjI1MTA3MjgzLCJleHAiOjE2MjUxMTQ0ODMsInVzZXIiOiJhZG1pbiIsInR5cGUiOiJhY2Nlc3MifQ.zx5bZTfpw9YATvHs6z2ks7lpWQDfbrbz2-kq9zy32U4'}
Jul 01 2021 12:41:56.900334 [DBG 1] perf: Starting for frame:alarm
Jul 01 2021 12:41:56.900545 [DBG 1] Sequence of detection types to execute: ['object']
Jul 01 2021 12:41:56.900821 [DBG 1] ============ Frame: alarm Running object detection type in sequence ==================
Jul 01 2021 12:41:56.901869 [DBG 2] Loading sequence: TPU object detection
Jul 01 2021 12:41:56.901955 [DBG 2] Initializing model  type:object with options:{'name': 'TPU object detection', 'enabled': 'yes', 'object_weights': '/var/lib/zmeventnotification/models/coral_edgetpu/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite', 'object_labels': '/var/lib/zmeventnotification/models/coral_edgetpu/coco_indexed.names', 'object_min_confidence': 0.6, 'object_framework': 'coral_edgetpu', 'tpu_max_processes': 1, 'tpu_max_lock_wait': 120, 'max_detection_size': '100%', 'show_models': 'yes', 'disable_locks': 'no'}
Jul 01 2021 12:41:56.918571 [DBG 2] portalock: max:1, name:pyzm_uid0_tpu_lock, timeout:120
Jul 01 2021 12:41:56.918754 [DBG 2] Loading sequence: YoloV4 GPU/CPU
Jul 01 2021 12:41:56.918800 [DBG 2] Initializing model  type:object with options:{'name': 'YoloV4 GPU/CPU', 'enabled': 'yes', 'object_config': '/var/lib/zmeventnotification/models/yolov4/yolov4.cfg', 'object_weights': '/var/lib/zmeventnotification/models/yolov4/yolov4.weights', 'object_labels': '/var/lib/zmeventnotification/models/yolov4/coco.names', 'object_min_confidence': 0.3, 'object_framework': 'opencv', 'object_processor': 'cpu', 'gpu_max_processes': 1, 'gpu_max_lock_wait': 120, 'cpu_max_processes': 2, 'cpu_max_lock_wait': 120, 'max_detection_size': '100%', 'show_models': 'yes', 'disable_locks': 'no'}
Jul 01 2021 12:41:56.919456 [DBG 2] portalock: max:2, name:pyzm_uid0_cpu_lock, timeout:120
Jul 01 2021 12:41:56.919521 [DBG 2] Waiting for pyzm_uid0_tpu_lock portalock...
Jul 01 2021 12:41:56.919814 [DBG 2] Got pyzm_uid0_tpu_lock portalock
Jul 01 2021 12:41:56.919839 [DBG 2] Waiting for pyzm_uid0_cpu_lock portalock...
Jul 01 2021 12:41:56.919947 [DBG 2] Got pyzm_uid0_cpu_lock portalock
Jul 01 2021 12:41:56.919970 [DBG 3] object has a same_model_sequence strategy of first
Jul 01 2021 12:41:56.919987 [DBG 3] --------- Frame:alarm Running variation: #1 -------------
Jul 01 2021 12:41:56.921862 [DBG 2] pyzm_uid0_tpu_lock portalock already acquired
Jul 01 2021 12:41:56.921919 [DBG 1] |--------- Loading "TPU object detection" model from disk -------------|
Jul 01 2021 12:41:59.611123 [DBG 1] perf: processor:tpu TPU initialization (loading /var/lib/zmeventnotification/models/coral_edgetpu/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite from disk) took: 2689.15 ms
Jul 01 2021 12:41:59.611221 [DBG 1] |---------- TPU (input image: 800w*450h) ----------|
Jul 01 2021 12:41:59.647217 [DBG 2] Released portalock pyzm_uid0_tpu_lock
Jul 01 2021 12:41:59.647296 [DBG 1] perf: processor:tpu Coral TPU detection took: 35.90 ms
Jul 01 2021 12:41:59.647346 [DBG 3] Coral object returning: [[326, 9, 408, 53]],['car'],[0.6171875]
Jul 01 2021 12:41:59.647563 [DBG 2] core model detection over, got 1 objects. Now filtering
Jul 01 2021 12:41:59.647595 [DBG 2] Max object size found to be: 100%
Jul 01 2021 12:41:59.648006 [DBG 2] Converted 100% to 360000.0
Jul 01 2021 12:41:59.648043 [DBG 2] Returning filtered list of 1 objects.
Jul 01 2021 12:41:59.648071 [DBG 2] This model iteration inside object found: labels: ['car'],conf:[0.6171875]
Jul 01 2021 12:41:59.648097 [DBG 2] Max object size found to be: 100%
Jul 01 2021 12:41:59.648127 [DBG 2] Converted 100% to 360000.0
Jul 01 2021 12:41:59.648161 [DBG 2] No polygons, adding full image polygon: {'name': 'full_image', 'value': [(0, 0), (640, 0), (640, 360), (0, 360)], 'pattern': None}
Jul 01 2021 12:41:59.648203 [DBG 3] resized polygons x=1.25/y=1.25: [{'name': 'full_image', 'value': [(0, 0), (800, 0), (800, 450), (0, 450)], 'pattern': None}]
Jul 01 2021 12:41:59.648641 [DBG 2] intersection: comparing object:car,POLYGON ((326 9, 408 9, 408 53, 326 53, 326 9)) to polygon:full_image,POLYGON ((0 0, 800 0, 800 450, 0 450, 0 0))
Jul 01 2021 12:41:59.648734 [DBG 2] Match pattern overridden to (person|car|motorbike|bus|truck|cat|dog) in ml_overrides
Jul 01 2021 12:41:59.649094 [DBG 2] full_image intersects object:car[[(326, 9), (408, 9), (408, 53), (326, 53)]]
Jul 01 2021 12:41:59.649145 [DBG 2] breaking out of same model loop, as matches found and strategy is "first"
Jul 01 2021 12:41:59.649481 [DBG 3] Reading http://xxxxxxxxxxx/zm/index.php?view=image&eid=34373&fid=snapshot
Jul 01 2021 12:41:59.649532 [DBG 3] No need to relogin as access token still has 119.39027066666667 minutes remaining
Jul 01 2021 12:41:59.649574 [DBG 3] make_request called with url=http://xxxxxxxxxxx/zm/index.php?view=image&eid=34373&fid=snapshot payload={} type=get query={'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJab25lTWluZGVyIiwiaWF0IjoxNjI1MTA3MjgzLCJleHAiOjE2MjUxMTQ0ODMsInVzZXIiOiJhZG1pbiIsInR5cGUiOiJhY2Nlc3MifQ.zx5bZTfpw9YATvHs6z2ks7lpWQDfbrbz2-kq9zy32U4'}
Jul 01 2021 12:41:59.695084 [DBG 1] perf: Starting for frame:snapshot
Jul 01 2021 12:41:59.695176 [DBG 1] Sequence of detection types to execute: ['object']
Jul 01 2021 12:41:59.695203 [DBG 1] ============ Frame: snapshot Running object detection type in sequence ==================
Jul 01 2021 12:41:59.695228 [DBG 3] object has a same_model_sequence strategy of first
Jul 01 2021 12:41:59.695247 [DBG 3] --------- Frame:snapshot Running variation: #1 -------------
Jul 01 2021 12:41:59.698239 [DBG 2] Waiting for pyzm_uid0_tpu_lock portalock...
Jul 01 2021 12:41:59.698568 [DBG 2] Got pyzm_uid0_tpu_lock portalock
Jul 01 2021 12:41:59.698604 [DBG 1] |---------- TPU (input image: 800w*450h) ----------|
Jul 01 2021 12:41:59.722657 [DBG 2] Released portalock pyzm_uid0_tpu_lock
Jul 01 2021 12:41:59.722716 [DBG 1] perf: processor:tpu Coral TPU detection took: 23.97 ms
Jul 01 2021 12:41:59.722747 [DBG 3] Coral object returning: [[326, 8, 408, 52]],['car'],[0.62890625]
Jul 01 2021 12:41:59.723017 [DBG 2] core model detection over, got 1 objects. Now filtering
Jul 01 2021 12:41:59.723036 [DBG 2] Max object size found to be: 100%
Jul 01 2021 12:41:59.723072 [DBG 2] Converted 100% to 360000.0
Jul 01 2021 12:41:59.723094 [DBG 2] Returning filtered list of 1 objects.
Jul 01 2021 12:41:59.723114 [DBG 2] This model iteration inside object found: labels: ['car'],conf:[0.62890625]
Jul 01 2021 12:41:59.723142 [DBG 2] Max object size found to be: 100%
Jul 01 2021 12:41:59.723182 [DBG 2] Converted 100% to 360000.0
Jul 01 2021 12:41:59.723510 [DBG 2] intersection: comparing object:car,POLYGON ((326 8, 408 8, 408 52, 326 52, 326 8)) to polygon:full_image,POLYGON ((0 0, 800 0, 800 450, 0 450, 0 0))
Jul 01 2021 12:41:59.723560 [DBG 2] Match pattern overridden to (person|car|motorbike|bus|truck|cat|dog) in ml_overrides
Jul 01 2021 12:41:59.723591 [DBG 2] full_image intersects object:car[[(326, 8), (408, 8), (408, 52), (326, 52)]]
Jul 01 2021 12:41:59.723619 [DBG 2] breaking out of same model loop, as matches found and strategy is "first"
Jul 01 2021 12:41:59.724111 [DBG 2] pyzm_uid0_tpu_lock portalock already released
Jul 01 2021 12:41:59.724184 [DBG 2] Released pyzm_uid0_cpu_lock portalock
Jul 01 2021 12:41:59.724215 [DBG 1] perf: TOTAL detection sequence (with image loads) took: 2999.54 ms  to process 34373
Jul 01 2021 12:41:59.724516 [DBG 1] Returning {'matched_data': {'boxes': [[326, 9, 408, 53]], 'error_boxes': [], 'labels': ['car'], 'confidences': [0.6171875], 'frame_id': 'alarm', 'model_names': ['coral'], 'image_dimensions': {'original': (360, 640), 'resized': (450, 800)}, 'image': None, 'polygons': [{'name': 'full_image', 'value': [(0, 0), (800, 0), (800, 450), (0, 450)], 'pattern': None}]}, 'all_matches': [{'frame_id': 'alarm', 'boxes': [[326, 9, 408, 53]], 'error_boxes': [], 'labels': ['car'], 'confidences': [0.6171875], 'detection_types': ['object'], 'model_names': ['coral']}, {'frame_id': 'snapshot', 'boxes': [[326, 8, 408, 52]], 'error_boxes': [], 'labels': ['car'], 'confidences': [0.62890625], 'detection_types': ['object'], 'model_names': ['coral']}]}
Last edited by VicThor on Thu Jul 01, 2021 8:39 pm, edited 1 time in total.
juan11perez
Posts: 64
Joined: Tue Apr 27, 2021 3:41 am

Re: zmevennotification object detection on edge tpu

Post by juan11perez »

I might be wrong but I understood below setting is what you need to stop static items events.

Code: Select all

# 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=no
Moreover, mlapi has been updated to incorporate the previously suggested fix for the out of place boxes.

Code: Select all

		# if yes, will convert 'snapshot' to a specific frame id
		# This is useful because you may see boxes drawn at the wrong places when using mlapi 
		# This is because when mlapi detects an image, a 'snapshot' could point to, say, frame 45
		# But when zm_detect gets the detections back and draws the boxes, snapshot could have moved 
		# to frame 50 (example). Enabling this makes sure mlapi tells zm_detect which frame id to use
		# default is 'no'
		'convert_snapshot_to_fid': 'yes',

I've updated docker accordingly
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmevennotification object detection on edge tpu

Post by asker »

VicThor wrote: Thu Jul 01, 2021 2:44 am Cheers, finally have it spewing:

Jul 01 2021 12:41:56.718392 [DBG 1] Hashes are correct: password matched
Jul 01 2021 12:41:56.723684 [DBG 1] Monitor ID not specified, or not found in mlapi config, using zm_detect overrides
<deleted>
So if you look at your mlapi logs, there are no mentions of match_past_detections
I just turned on match_patch_detections in mlapi and ran a detection (remember mlapi keeps running, so you'll have to restart after config changes)

Round 1:

Code: Select all

sudo -u www-data ./hook/zm_detect.py --config /etc/zm/objectconfig.ini  --eventid 48677 --monitorid 3  --debug 

07/01/21 06:59:00 zm_mlapi[1644765] INF detect_sequence.py:794 [Removing matches to past detections for monitor:3]
07/01/21 06:59:00 zm_mlapi[1644765] DBG2 detect_sequence.py:236 [trying to load /var/lib/zmeventnotification/images/monitor-3-data.pkl]
07/01/21 06:59:00 zm_mlapi[1644765] DBG3 detect_sequence.py:283 [Globals:past detection:use_percent:False, max_diff_area:0]
07/01/21 06:59:00 zm_mlapi[1644765] DBG2 detect_sequence.py:344 [match_past_detections: Comparing  saved person@[(195, 145), (770, 145), (770, 1000), (195, 1000)] to person@[(348, 440), (728, 440), (728, 1014), (348, 1014)]]
07/01/21 06:59:00 zm_mlapi[1644765] DBG2 detect_sequence.py:362 [Diff area of:278825.0 > max_diff_pixels:0 for person@[(348, 440), (728, 440), (728, 1014), (348, 1014)], allowing it]

Round 2 on the same event:

Code: Select all

sudo -u www-data ./hook/zm_detect.py --config /etc/zm/objectconfig.ini  --eventid 48677 --monitorid 3  --debug 

07/01/21 06:59:39 zm_mlapi[1644765] DBG2 detect_sequence.py:344 [match_past_detections: Comparing  saved person@[(348, 440), (728, 440), (728, 1014), (348, 1014)] to person@[(348, 440), (728, 440), (728, 1014), (348, 1014)]]
07/01/21 06:59:39 zm_mlapi[1644765] DBG1 detect_sequence.py:356 [past detection person@[(348, 440), (728, 440), (728, 1014), (348, 1014)] approximately matches person@[(348, 440), (728, 440), (728, 1014), (348, 1014)] removing]
07/01/21 06:59:39 zm_mlapi[1644765] DBG1 detect_sequence.py:372 [Saving detections for monitor 3 for future match]
07/01/21 06:59:39 zm_mlapi[1644765] DBG2 detect_sequence.py:380 [saving boxes:[[348, 440, 728, 1014]], labels:['person'] confs:[0.83984375] to /var/lib/zmeventnotification/images/monitor-3-data.pkl]
As you see past detections works fine in mlapi

Here is my full ml section, incase you can spot differences

Code: Select all

[ml]
# if enabled, will not grab exclusive locks before running inferencing
# locking seems to cause issues on some unique file systems
disable_locks = no
my_frame_strategy = most_models

use_sequence = yes

stream_sequence = {
		'frame_strategy': '{{my_frame_strategy}}',
		'frame_set': 'snapshot,alarm',
		'contig_frames_before_error': 5,
		'max_attempts': 3,
		'sleep_between_attempts': 4,
		'delay_between_frames':0,
		'convert_snapshot_to_fid':'yes',
		'resize':800
	}

ml_sequence= {
		'general': {
			'model_sequence': '{{model_sequence}}',
			'disable_locks': '{{disable_locks}}',
			'match_past_detections':'yes',
		},
		'object': {
			'general':{
				'pattern':'{{object_detection_pattern}}',
				'same_model_sequence_strategy': 'most_unique' # also 'most', 'most_unique's
			},
			'sequence': [{
				#First run on TPU with higher confidence
				#'maxsize':320,
				'name': 'TPU object detection',
				'enabled': 'yes',
				'object_weights':'{{tpu_object_weights_mobiledet}}',
				'object_labels': '{{tpu_object_labels}}',
				'object_min_confidence': {{tpu_min_confidence}},
				'object_framework':'{{tpu_object_framework}}',
				'tpu_max_processes': {{tpu_max_processes}},
				'tpu_max_lock_wait': {{tpu_max_lock_wait}},
				'max_detection_size':'{{max_detection_size}}',

				
			},
			{
				# YoloV4 on GPU if TPU fails (because sequence strategy is 'first')
				'name': 'YoloV4 GPU/CPU object detection',
				'enabled': 'yes',
				'object_config':'{{yolo4_object_config}}',
				'object_weights':'{{yolo4_object_weights}}',
				'object_labels': '{{yolo4_object_labels}}',
				'object_min_confidence': {{object_min_confidence}},
				'object_framework':'{{yolo4_object_framework}}',
				'object_processor': '{{yolo4_object_processor}}',
				'gpu_max_processes': {{gpu_max_processes}},
				'gpu_max_lock_wait': {{gpu_max_lock_wait}},
				'cpu_max_processes': {{cpu_max_processes}},
				'cpu_max_lock_wait': {{cpu_max_lock_wait}},
				'max_detection_size':'{{max_detection_size}}',

			}]
		},
		'face': {
			'general':{
				'pattern': '{{face_detection_pattern}}',
				'same_model_sequence_strategy': 'first'
			},
			'sequence': [{
				'name': 'Dlib Face Detection',
				'enabled': 'yes',
				'save_unknown_faces':'{{save_unknown_faces}}',
				'save_unknown_faces_leeway_pixels':{{save_unknown_faces_leeway_pixels}},
				'face_detection_framework': '{{face_detection_framework}}',
				'known_images_path': '{{known_images_path}}',
				'unknown_images_path': '{{unknown_images_path}}',
				'face_model': '{{face_model}}',
				'face_train_model': '{{face_train_model}}',
				'face_recog_dist_threshold': {{face_recog_dist_threshold}},
				'face_num_jitters': {{face_num_jitters}},
				'face_upsample_times':{{face_upsample_times}},
				'gpu_max_processes': {{gpu_max_processes}},
				'gpu_max_lock_wait': {{gpu_max_lock_wait}},
				'cpu_max_processes': {{cpu_max_processes}},
				'cpu_max_lock_wait': {{cpu_max_lock_wait}},
				'max_size':800
			},
			{
				'name': 'Face Detection (TPU)',
				'enabled': 'no',
				'face_detection_framework': 'tpu',
				'face_weights':'/var/lib/zmeventnotification/models/coral_edgetpu/ssd_mobilenet_v2_face_quant_postprocess_edgetpu.tflite',
				'face_min_confidence': 0.3
			
			}]
		},

		'alpr': {
			'general':{
				'same_model_sequence_strategy': 'first',
				'pre_existing_labels':['car', 'motorbike', 'bus', 'truck', 'boat'],
				'pattern': '{{alpr_detection_pattern}}'

			},
			'sequence': [{
				'alpr_api_type': '{{alpr_api_type}}',
				'alpr_service': '{{alpr_service}}',
				'alpr_key': '{{alpr_key}}',
				'platrec_stats': '{{platerec_stats}}',
				'platerec_min_dscore': {{platerec_min_dscore}},
				'platerec_min_score': {{platerec_min_score}},
				'max_size':1600
			}]
		}
	}

Now why it is not working for you:
- I'm not quite sure, I don't know how that docker works, where it picks configs from, whether it is picking up your changes etc. Best discussed with the author of that docker.

Finally, when posting code or debug logs, please encapsulate them in code blocks, or post in a gist and link here
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
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zmevennotification object detection on edge tpu

Post by asker »

1. The most important thing is "match_patch_detections" as specified is just a variable. It also needs to be part of the general section of ml_sequence - a 'yes' or 'no' there is what actually matters. This section covers it, but I know its confusing. This is because when I first started, just adding this attribute somewhere in config made sure it worked. Now, unless it is specified inside ml_sequence it will be ignored.

2. You are running mlapi without debug logs. You may want to configure your docker in a way that mlapi is able to store debug logs using a configuration variable the user can set up.
juan11perez wrote: Thu Jul 01, 2021 5:36 am I might be wrong but I understood below setting is what you need to stop static items events.

Code: Select all

# 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=no
Moreover, mlapi has been updated to incorporate the previously suggested fix for the out of place boxes.

Code: Select all

		# if yes, will convert 'snapshot' to a specific frame id
		# This is useful because you may see boxes drawn at the wrong places when using mlapi 
		# This is because when mlapi detects an image, a 'snapshot' could point to, say, frame 45
		# But when zm_detect gets the detections back and draws the boxes, snapshot could have moved 
		# to frame 50 (example). Enabling this makes sure mlapi tells zm_detect which frame id to use
		# default is 'no'
		'convert_snapshot_to_fid': 'yes',

I've updated docker accordingly
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
juan11perez
Posts: 64
Joined: Tue Apr 27, 2021 3:41 am

Re: zmevennotification object detection on edge tpu

Post by juan11perez »

Thank you. As I said this docker is my first attempt at building one.
I'll have to research on logs, as I dont know how to do that.
VicThor
Posts: 39
Joined: Tue Oct 13, 2020 8:47 pm

Re: zmevennotification object detection on edge tpu

Post by VicThor »

Thank you asked/juan11perez

I've added the following and the bounding boxes are right (maybe because of the width resize they were wrong?):

Code: Select all

stream_sequence = {
                'frame_strategy': 'most_models',
                'frame_set': 'snapshot,alarm',
                'contig_frames_before_error': 5,
                'max_attempts': 3,
                'sleep_between_attempts': 0,
                'delay_between_frames':0,
                'convert_snapshot_to_fid':'yes',
                'resize': 'no',
Not sure if match_past_detection works, does not seem like it.

@juan11perez if you can have mlapi.py as service instead of manual logging should work.
I was thinking to do a >> file.log but then there is no log rotation.
juan11perez
Posts: 64
Joined: Tue Apr 27, 2021 3:41 am

Re: zmevennotification object detection on edge tpu

Post by juan11perez »

If I type the following command into the zoneminder docker i get the below output. It's working fine.

Code: Select all

sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py --config /etc/zm/objectconfig.ini  --eventid 27946 --monitorid 2  --debug >> zmevent.log

Code: Select all

07/02/21 05:51:58 zmesdetect_m2[22376] INF ZMLog.py:291 [Setting up signal handler for logs]
07/02/21 05:51:58 zmesdetect_m2[22376] INF ZMLog.py:300 [Switching global logger to ZMLog]
07/02/21 05:51:58 zmesdetect_m2[22376] INF zm_detect.py:284 [---------| app:6.1.25, pyzm:0.3.50, ES:6.1.25
 , OpenCV:4.5.2|------------]
07/02/21 05:51:58 zmesdetect_m2[22376] INF utils.py:405 [Reading config from: /etc/zm/objectconfig.ini]
07/02/21 05:51:58 zmesdetect_m2[22376] INF utils.py:410 [Reading secrets from: /etc/zm/secrets.ini]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:382 [Secret token found in config: !ZM_PORTAL]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:382 [Secret token found in config: !ZM_USER]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:382 [Secret token found in config: !ZM_PASSWORD]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:382 [Secret token found in config: !ZM_API_PORTAL]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:382 [Secret token found in config: !ML_USER]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:382 [Secret token found in config: !ML_PASSWORD]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:382 [Secret token found in config: !PLATEREC_ALPR_KEY]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG1 utils.py:445 [allowing self-signed certs to work...]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 utils.py:455 [Now checking for monitor overrides]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG3 utils.py:473 [[monitor-2] overrides key:match_past_detections with value:yes]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG3 utils.py:473 [[monitor-2] overrides key:object_detection_pattern with value:(person)]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG3 utils.py:522 [Finally, doing parameter substitution]
07/02/21 05:51:58 zmesdetect_m2[22376] INF zm_detect.py:313 [Importing remote shim classes for Object/Face]
07/02/21 05:51:58 zmesdetect_m2[22376] INF zm_detect.py:334 [Connecting with ZM APIs]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 api.py:72 [API SSL certificate check has been disbled]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG1 api.py:181 [using username/password for login]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 api.py:210 [Using new token API]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG1 api.py:217 [Access token expires on:2021-07-02 07:51:58.432450 [7200s]]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG1 api.py:221 [Refresh token expires on:2021-07-03 05:51:58.432754 [86400s]]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 zm_detect.py:342 [using ml_sequence]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 zm_detect.py:354 [using stream_sequence]
07/02/21 05:51:58 zmesdetect_m2[22376] INF zm_detect.py:48 [Detecting using remote API Gateway http://192.168.1.100:5002/api/v1]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 zm_detect.py:57 [Found token file, checking if token has not expired]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG1 zm_detect.py:78 [Access token is valid for 698 more seconds]
07/02/21 05:51:58 zmesdetect_m2[22376] DBG2 zm_detect.py:141 [Invoking mlapi with url:http://192.168.1.100:5002/api/v1/detect/object?type=object and json: mid=2 reason=None stream=27946, stream_options={'frame_strategy': 'most_models', 'frame_set': 'snapshot,alarm', 'contig_frames_before_error': 5, 'max_attempts': 3, 'sleep_between_attempts': 4, 'resize': 800, 'api': None, 'polygons': []} ml_overrides={'model_sequence': 'object,face,alpr', 'object': {'pattern': '(person)'}, 'face': {'pattern': '.*'}, 'alpr': {'pattern': '.*'}} headers={'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MjUxOTAwMTksIm5iZiI6MTYyNTE5MDAxOSwianRpIjoiNzE1NDFmOTQtZjUzNy00NzZiLThhYWItYjBkMTdlNGI1N2I3IiwiZXhwIjoxNjI1MTkzNjE5LCJpZGVudGl0eSI6Imp1YW4xMXBlcmV6IiwiZnJlc2giOmZhbHNlLCJ0eXBlIjoiYWNjZXNzIn0.T2ShKKEfxxT6esvKtYEy2l_4QsYcAHTBZnHMJZf7qSk'} params={'delete': True, 'response_format': 'zm_detect'} ]
07/02/21 05:51:59 zmesdetect_m2[22376] DBG1 zm_detect.py:165 [remote detection inferencing took: 0:00:00.691893]
07/02/21 05:51:59 zmesdetect_m2[22376] DBG2 zm_detect.py:174 [Grabbing image from http://192.168.1.100:8088/zm/index.php?view=image&eid=27946&fid=alarm as we need to write objdetect.jpg]
07/02/21 05:51:59 zmesdetect_m2[22376] DBG3 api.py:144 [No need to relogin as access token still has 119.98835246666665 minutes remaining]
07/02/21 05:51:59 zmesdetect_m2[22376] DBG3 api.py:272 [make_request called with url=http://192.168.1.100:8088/zm/index.php?view=image&eid=27946&fid=alarm payload={} type=get query={'token': '<>>'}]
07/02/21 05:51:59 zmesdetect_m2[22376] DBG2 zm_detect.py:185 [Resizing source image from width=1280 to width=800 in zm_detect as that is the size mlapi used]
07/02/21 05:51:59 zmesdetect_m2[22376] DBG1 zm_detect.py:403 [Total remote detection detection took: 0:00:00.715404]
07/02/21 05:51:59 zmesdetect_m2[22376] DBG1 zm_detect.py:557 [Closing logs]
VicThor
Posts: 39
Joined: Tue Oct 13, 2020 8:47 pm

Re: zmevennotification object detection on edge tpu

Post by VicThor »

Think you need it on mlapi container where you launch mlapi.py
Post Reply