robmarkcole / HASS-Deepstack-object

Home Assistant custom component for using Deepstack object detection
https://community.home-assistant.io/t/face-and-person-detection-with-deepstack-local-and-free/92041
MIT License
437 stars 97 forks source link

image_processing.object_detected events volume quite large #48

Closed lmamakos closed 5 years ago

lmamakos commented 5 years ago

I was poking around at things, and noticed that my Home Assistant database was somewhat larger than I expected. While I have some cleaning up to do elsewhere, there's a very large number of events from this integration. Behold:

sqlite> select event_type,count(event_type) from events group by event_type;
automation_triggered|444
call_service|1468
image_processing.file_saved|37
image_processing.object_detected|110861
logbook_entry|17
state_changed|169292
sqlite>

Most of these are detections with quite low confidence.

sqlite> select * from events where event_type != 'state_changed' order by time_fired desc limit 20;
57841181|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam7_coral", "object": "tie", "confidence": 6.6}|LOCAL|2019-08-25 17:28:03.447058|2019-08-25 17:28:03.470214|dff50d142b354c169c2ac287a6edc783|
57841180|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam7_coral", "object": "tie", "confidence": 6.6}|LOCAL|2019-08-25 17:28:03.446988|2019-08-25 17:28:03.464997|d13d086d11f6457d81800150f8adb10a|
57841179|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam7_coral", "object": "bench", "confidence": 9.0}|LOCAL|2019-08-25 17:28:03.446906|2019-08-25 17:28:03.458613|23e353387a984a20bc2e57064530412e|
57841178|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam7_coral", "object": "bench", "confidence": 12.1}|LOCAL|2019-08-25 17:28:03.446749|2019-08-25 17:28:03.452756|e9e9aa9c854e4e4b8ae270b81ab22cbe|
57841176|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam9_coral", "object": "car", "confidence": 16.0}|LOCAL|2019-08-25 17:28:03.347528|2019-08-25 17:28:03.352460|0c1287f834854763804f7cc52e942105|
57841174|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam8_coral", "object": "tv", "confidence": 6.6}|LOCAL|2019-08-25 17:28:03.274874|2019-08-25 17:28:03.286495|1b18abd6361a4dbea42ee6d641ebe39d|
57841173|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam8_coral", "object": "car", "confidence": 34.0}|LOCAL|2019-08-25 17:28:03.274721|2019-08-25 17:28:03.278598|2b22fe4ae0f64a38970ac3536ffd9db5|
57841171|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "potted plant", "confidence": 12.1}|LOCAL|2019-08-25 17:28:03.143938|2019-08-25 17:28:03.213783|dbc9fa1a333e4ee183a21522f12eb711|
57841170|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "potted plant", "confidence": 12.1}|LOCAL|2019-08-25 17:28:03.143875|2019-08-25 17:28:03.208738|d6f30dedc01d4cf69db04f0cc3a2df72|
57841169|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "car", "confidence": 16.0}|LOCAL|2019-08-25 17:28:03.143812|2019-08-25 17:28:03.202402|976b6e6516454d83b83ac50db4b3520e|
57841168|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "chair", "confidence": 16.0}|LOCAL|2019-08-25 17:28:03.143750|2019-08-25 17:28:03.196763|f4d08f5afb0044fca90bad6ccf80de14|
57841167|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "potted plant", "confidence": 16.0}|LOCAL|2019-08-25 17:28:03.143686|2019-08-25 17:28:03.189965|e904fcf2753947f1adcd8a95954c6451|
57841166|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "car", "confidence": 16.0}|LOCAL|2019-08-25 17:28:03.143623|2019-08-25 17:28:03.183431|65051ac45d7c426e8213a1344f236418|
57841165|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "car", "confidence": 21.1}|LOCAL|2019-08-25 17:28:03.143544|2019-08-25 17:28:03.175894|e18e70b28ab049a8bee3cb6f312057e8|
57841164|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "car", "confidence": 34.0}|LOCAL|2019-08-25 17:28:03.143449|2019-08-25 17:28:03.170582|cc5f2f1170f5440e9b27f8346482f605|
57841163|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "potted plant", "confidence": 50.0}|LOCAL|2019-08-25 17:28:03.143374|2019-08-25 17:28:03.164434|112eee9f915f425a8c4e6c0503961fa9|
57841162|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam6_coral", "object": "chair", "confidence": 58.2}|LOCAL|2019-08-25 17:28:03.143228|2019-08-25 17:28:03.146986|4607dcb4a4344848bd8a83353da42471|
57841160|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam5_coral", "object": "bench", "confidence": 12.1}|LOCAL|2019-08-25 17:28:02.819882|2019-08-25 17:28:02.910808|e083b66394944b52901a86da285e613f|
57841159|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam5_coral", "object": "potted plant", "confidence": 12.1}|LOCAL|2019-08-25 17:28:02.819814|2019-08-25 17:28:02.903817|214259526cc7437aa46d1f8924b0ba87|
57841158|image_processing.object_detected|{"classifier": "deepstack_object", "entity_id": "image_processing.cam5_coral", "object": "potted plant", "confidence": 12.1}|LOCAL|2019-08-25 17:28:02.819745|2019-08-25 17:28:02.887147|037e2411a3984ce18de031efbe093731|
sqlite>

It might be nice to reduce the volume of these events that are generated and thrown through the Home Assistant state machine. What comes to my mind is some combination of these to reduce the overall volume of events generated:

I'm sure what's best in the spirit of things here, and the impact of other models that might work differently. Of course, I can also blacklist that service from the recorder database, but there remains a concern about the default behavior of shoving all the events into the database that we might want to consider?

robmarkcole commented 5 years ago

All of this info is within the attributes of the sensor but it is a hassle to break them out, which is why I added the events per detection. I agree the best solution is to fire events only above the confidence threshold.

robmarkcole commented 5 years ago

Addressed in https://github.com/robmarkcole/HASS-Deepstack-object/releases/tag/v1.3