ZoneMinder / mlapi

An easy to use/extend object recognition API you can locally install. Python+Flask. Also works with ZMES!
Other
58 stars 35 forks source link

face detection saves unknown face then bugs out #22

Closed hugalafutro closed 3 years ago

hugalafutro commented 3 years ago

Hi, I got ZM stable in docker up and detecting persons via coral on mlapi with yolov4 local fallback + working zmeventnotifications+zmninja. Trying to add face recognition to the mix I'm getting an error, although the recognition itself works correctly as the face gets saved into unknown_faces folder, but after that I receive following error in mlapi_error.log:

 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
172.17.0.4 - - [29/Nov/2020 19:10:22] "POST /api/v1/detect/object?type=object&delete=True HTTP/1.1" 200 -
172.17.0.4 - - [29/Nov/2020 19:10:50] "POST /api/v1/detect/object?type=face&delete=True HTTP/1.1" 200 -
172.17.0.4 - - [29/Nov/2020 19:10:50] "POST /api/v1/detect/object?type=face_names HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 323, in run_wsgi
    execute(self.server.app)
  File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 312, in execute
    application_iter = app(environ, start_response)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 272, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 272, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/_compat.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 468, in wrapper
    resp = resource(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 583, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/flask_jwt_extended/view_decorators.py", line 108, in wrapper
    return fn(*args, **kwargs)
  File "/home/sammael/mlapi/mlapi.py", line 106, in post
    'names': face_obj.get_classes().tolist()
AttributeError: 'list' object has no attribute 'tolist'

and in zoneminder log:

zoneminder    | Nov 29 19:10:50 b23435ec1b9d /zm_detect.py[33997]: FAT [zmesdetect_m2] [Unrecoverable error:Expecting value: line 1 column 1 (char 0) Traceback:Traceback (most recent call last):
zoneminder    |   File "/var/lib/zmeventnotification/bin/zm_detect.py", line 852, in <module>
zoneminder    |     main_handler()
zoneminder    |   File "/var/lib/zmeventnotification/bin/zm_detect.py", line 457, in main_handler
zoneminder    |     data = r.json()
zoneminder    |   File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 900, in json
zoneminder    |     return complexjson.loads(self.text, **kwargs)
zoneminder    |   File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
zoneminder    |     return _default_decoder.decode(s)
zoneminder    |   File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
zoneminder    |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
zoneminder    |   File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
zoneminder    |     raise JSONDecodeError("Expecting value", s, err.value) from None
zoneminder    | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
zoneminder    | ]

but mlapi.log makes it look as if everything went ok so I'm not really sure which part of the whole setup is failing:

INFO: --------| mlapi version:2.0.0 |--------
INFO: Starting server with max:3 processes
 * Serving Flask app "mlapi" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
DEBUG: Object Recognition requested
DEBUG: get_file returned: ./images/c008d257-65ec-47bc-8fda-b5757d351386.jpg
Nov 29 2020 19:10:20.213197 [DBG 1] Waiting for TPU lock...
Nov 29 2020 19:10:20.215382 [DBG 1] Got TPU Lock
Nov 29 2020 19:10:20.215412 [DBG 1] Loading TPU model from disk
Nov 29 2020 19:10:22.924630 [DBG 1] TPU initialization (loading model from disk) took: 709.172 milliseconds
Nov 29 2020 19:10:22.924706 [DBG 1] |---------- TPU (input image: 1200w*675h) ----------|
Nov 29 2020 19:10:22.952415 [DBG 1] Released TPU lock
Nov 29 2020 19:10:22.952499 [DBG 1] Coral TPU detection took: 27.611 milliseconds
Nov 29 2020 19:10:22.952605 [DBG 2] core model detection over, got 3 objects. Now filtering
Nov 29 2020 19:10:22.952631 [DBG 3] Max object size found to be: 100%
Nov 29 2020 19:10:22.952944 [DBG 2] Converted 100% to 810000.0
Nov 29 2020 19:10:22.952990 [DBG 1] Ignoring person [901, 208, 1105, 597] as conf. level 0.2109375 is lower than 0.3
Nov 29 2020 19:10:22.953018 [DBG 1] Ignoring clock [206, 8, 356, 278] as conf. level 0.2109375 is lower than 0.3
Nov 29 2020 19:10:22.953038 [DBG 2] Returning filtered list of 1 objects.
DEBUG: Face Recognition requested
DEBUG: get_file returned: ./images/a5e46389-e539-403f-a0e6-8b75afe22dc6.jpg
Nov 29 2020 19:10:23.001230 [DBG 1] |---------- Face recognition (input image: 1200w*675h) ----------|
Nov 29 2020 19:10:23.001324 [DBG 1] Waiting for cpu lock...
Nov 29 2020 19:10:23.001782 [DBG 1] Got cpu lock for initialization...
Nov 29 2020 19:10:23.001823 [DBG 1] init lock released
Nov 29 2020 19:10:50.018758 [DBG 1] Finding faces took 11.795 milliseconds
Nov 29 2020 19:10:50.215418 [DBG 1] pyzm_cpu_lock Lock already released
Nov 29 2020 19:10:50.215505 [DBG 1] Computing face recognition distances took 183.94 milliseconds
Nov 29 2020 19:10:50.215533 [DBG 1] No faces to match, so creating empty set
Nov 29 2020 19:10:50.215556 [DBG 1] Matching recognized faces to known faces took 0.022 milliseconds
Nov 29 2020 19:10:50.216098 [INF] Saving cropped unknown face at [1040,79,1197,236 - includes leeway of 50px] to ./unknown_faces/Nov29-19h10m50s-7d409ab3-4521-426d-b8bb-c77728559a6e.jpg
Nov 29 2020 19:10:50.229169 [DBG 1] FACE:Returning: [[1090, 129, 1147, 186]], ['unknown face'], [1]
DEBUG: List of face names requested
[]

however the unknown face pictures end up named such as Nov29-19h43m49s-57a4b9ab-dd4a-4870-80fc-5a9bc27553d9.jpg regardless of value of unknown_face_name in mlapiconfig.ini

pliablepixels commented 3 years ago

Getting back to issues that I forgot to respond (sorry). Lots of changes have occured. Does this still occur?

hugalafutro commented 3 years ago

Hi,

no worries as I forgot about this as well.

Since posting this a lot changed in my setup (got rid of the coral usb and swapped from mlapi back to local detection) as well as changes in zm, zmes, mlapi etc - not really sure if this issue still applies. I'll close it and try to set up the face detection over weekend provided I steal away some free time, and if it still happens I'll open new issue in relevant section as I don't use mlapi at the moment.