New Custom Compontent - Image Processing - Object Detection - DOODS

Hey thanks.

I’m out just now but will do it when I’m. back. Which model did you choose? I take it that you put the Coral into the USB 3.0?

Edit: Can you also post your DOODS config

I just made a few updates to DOODS. The repo now makes it easy to build tensorflow custom for the CPU you are running. (x86_64 only) It’s updated tensorflow and the Coral EdgeTPU drivers to something much more recent now that the drivers have been open sources. As well, the MUCH more accurate inception model is included by default. It’s actually pretty reasonable and runs in about 5 seconds on a raspberry pi 4.

4 Likes

Appreciate your work! Are you able to update the hass.io version?

Thank you

1 Like

Thank you for your work on this. Two questions.

I am running the latest Docker container and can’t figure out how to access the config file. I’m not familiar with Docker so bear with me. I believe I need to modify the “concurrent” and “threads” values to speed up the image processing but I can’t figure out how to modify or even locate the config file.

Second question is regarding GPU support. I am running Docker on a physical Windows Server 2019 machine with an i7-4790 and a GTX 1050 Ti card installed. Any updates on whether DOODS can utilize GPU resources yet?

I see the gRPC detectstream endpoint. Is there a way to detect objects from a video stream?

Is there any good way to retrain this?
For just out of the blue Doods went beserk and flagged the following things as Person and laptop.

pool_20200620_111636

I know that I can turn of object, but thats isn’t very helpful when it comes to persons.

1 Like

If you go to the link in the first post that says source for server is here and scroll down to the bottom of that page it says how to enable cuda support. I have yet to try it, but will as soon as I have time.

hello
i have a problem installing doods on hassio. i get the following message in the logs

Protokolldetails ( ERROR )
Logger: homeassistant.components.image_processing
Source: custom_components/doods/image_processing.py:100
Integration: Bildverarbeitung (documentation, issues)
First occurred: 21:52:18 (1 occurrences)
Last logged: 21:52:18

Error while setting up doods platform for image_processing
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection
    raise err
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, in create_connection
    sock.connect(sa)
OSError: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.7/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 187, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 172, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0xa893d7d0>: Failed to establish a new connection: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.178.153', port=8080): Max retries exceeded with url: /detectors (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xa893d7d0>: Failed to establish a new connection: [Errno 113] Host is unreachable'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/doods/image_processing.py", line 100, in setup_platform
    doods = PyDOODS(url, auth_key, timeout)
  File "/usr/local/lib/python3.7/site-packages/pydoods/__init__.py", line 13, in __init__
    self.get_detectors()
  File "/usr/local/lib/python3.7/site-packages/pydoods/__init__.py", line 20, in get_detectors
    response = requests.get(self.url + "/detectors", **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.178.153', port=8080): Max retries exceeded with url: /detectors (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xa893d7d0>: Failed to establish a new connection: [Errno 113] Host is unreachable'))

whats the problem?

It can’t reach your Doods add-on. Check the settings you used in HA, and that your add-on is running.

thanks. now its running

then i changed from default to inception and now i have these error.

Protokolldetails ( ERROR )
Logger: homeassistant.components.image_processing
Source: custom_components/doods/image_processing.py:100
Integration: Bildverarbeitung (documentation, issues)
First occurred: 18:06:50 (1 occurrences)
Last logged: 18:06:50

Error while setting up doods platform for image_processing
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection
    raise err
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.7/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 187, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 172, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0xa8a74cb0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=8080): Max retries exceeded with url: /detectors (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xa8a74cb0>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/doods/image_processing.py", line 100, in setup_platform
    doods = PyDOODS(url, auth_key, timeout)
  File "/usr/local/lib/python3.7/site-packages/pydoods/__init__.py", line 13, in __init__
    self.get_detectors()
  File "/usr/local/lib/python3.7/site-packages/pydoods/__init__.py", line 20, in get_detectors
    response = requests.get(self.url + "/detectors", **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8080): Max retries exceeded with url: /detectors (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xa8a74cb0>: Failed to establish a new connection: [Errno 111] Connection refused'))

this is my configuration.yaml

# Example advanced configuration.yaml entry
image_processing:
  - platform: doods
    scan_interval: 20
    url: "http://127.0.0.1:8080"
    timeout: 60
    detector: inception
    source:
      - entity_id: camera.entenkamera
    file_out:
      - "/config/www/doods/{{ camera_entity.split('.')[1] }}_latest.jpg"
      - "/config/www/doods/{{ camera_entity.split('.')[1] }}_{{ now().strftime('%Y%m%d_%H%M%S') }}.jpg"
    labels:
      - name: person
      - name: horse
      - name: bird

and this is the add-on config:

server:
  port: '8080'
auth_key: ''
doods.detectors:
  - name: default
    type: tflite
    modelFile: /opt/doods/models/coco_ssd_mobilenet_v1_1.0_quant.tflite
    labelFile: /opt/doods/models/coco_labels0.txt
    numThreads: 1
    numConcurrent: 1
    hwAccel: false
  - name: inception
    type: tensorflow
    modelFile: /share/doods/faster_rcnn_inception_v2_coco_2018_01_28.pb
    labelFile: /share/doods/coco_labels1.txt
    numThreads: 1
    numConcurrent: 1
    hwAccel: false

what is wrong??

If I were you I’d try to change the url to the actual IP address of the host rather than the 127.0.0.1.

ok thanks i changed it. but after starting Doods it shuts down after few minute with this errors :frowning:

Protokolldetails ( ERROR )
Logger: homeassistant.helpers.entity
Source: components/doods/image_processing.py:294
First occurred: 17:19:12 (1 occurrences)
Last logged: 17:19:12

Update for image_processing.doods_yicam fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 426, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.7/http/client.py", line 1344, in getresponse
    response.begin()
  File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.7/http/client.py", line 267, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 403, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 735, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 428, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 336, in _raise_timeout
    self, url, "Read timed out. (read timeout=%s)" % timeout_value
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='192.168.1.107', port=8080): Read timed out. (read timeout=60)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 272, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 463, in async_device_update
    await self.async_update()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/image_processing/__init__.py", line 132, in async_update
    await self.async_process_image(image.content)
  File "/usr/src/homeassistant/homeassistant/components/image_processing/__init__.py", line 112, in async_process_image
    return await self.hass.async_add_job(self.process_image, image)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/doods/image_processing.py", line 294, in process_image
    image, dconfig=self._dconfig, detector_name=self._detector_name
  File "/usr/local/lib/python3.7/site-packages/pydoods/__init__.py", line 30, in detect
    self.url + "/detect", json={"data": PyDOODS.encode_image(image), "detector_name": detector_name, "detect": dconfig, "id": id}, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 529, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='192.168.1.107', port=8080): Read timed out. (read timeout=60)

this is the log of doods

2020-07-15T17:33:10.424+0200	INFO	detector/detector.go:78	Configured Detector	{"package": "detector", "name": "tensorflow", "type": "tensorflow", "model": "/share/faster_rcnn_inception_v2_coco_2018_01_28.pb", "labels": 65, "width": -1, "height": -1}
2020-07-15T17:33:10.458+0200	INFO	server/server.go:274	API Listening	{"package": "server", "address": ":8080", "tls": false, "version": "v0.2.1-0-g91828a0-dirty"}
2020-07-15T17:34:18.807+0200	INFO	server/server.go:138	HTTP Request	{"status": 200, "took": 0.034315815, "request": "/detectors", "method": "GET", "package": "server.request", "request-id": "d5f40609-doods/mBKJO2GG2P-000001", "remote": "192.168.1.107:50832"}
2020-07-15T17:34:18.918+0200	INFO	server/server.go:138	HTTP Request	{"status": 200, "took": 0.00540873, "request": "/detectors", "method": "GET", "package": "server.request", "request-id": "d5f40609-doods/mBKJO2GG2P-000002", "remote": "192.168.1.107:50834"}
2020-07-15T18:16:11.369+0200	INFO	detector/detector.go:78	Configured Detector	{"package": "detector", "name": "tensorflow", "type": "tensorflow", "model": "/share/faster_rcnn_inception_v2_coco_2018_01_28.pb", "labels": 65, "width": -1, "height": -1}
2020-07-15T18:16:11.452+0200	INFO	server/server.go:274	API Listening	{"package": "server", "address": ":8080", "tls": false, "version": "v0.2.1-0-g91828a0-dirty"}
2020-07-15 18:16:17.320144: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 6220800 exceeds 10% of free system memory.
2020-07-15 18:16:25.473950: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 1441792 exceeds 10% of free system memory.
2020-07-15 18:16:25.511402: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 786432 exceeds 10% of free system memory.
2020-07-15 18:16:25.526146: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 2211840 exceeds 10% of free system memory.
2020-07-15 18:16:25.565658: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 786432 exceeds 10% of free system memory.

My config looks similar except I removed the default detector completely.
So where you have:

server:
  port: '8080'
auth_key: ''
doods.detectors:
  - name: default
    type: tflite
    modelFile: /opt/doods/models/coco_ssd_mobilenet_v1_1.0_quant.tflite
    labelFile: /opt/doods/models/coco_labels0.txt
    numThreads: 1
    numConcurrent: 1
    hwAccel: false
  - name: inception
    type: tensorflow
    modelFile: /share/doods/faster_rcnn_inception_v2_coco_2018_01_28.pb
    labelFile: /share/doods/coco_labels1.txt
    numThreads: 1
    numConcurrent: 1
    hwAccel: false

I have:

server:
  port: '8080'
auth_key: ''
doods.detectors:
    - name: inception
    type: tensorflow
    modelFile: /share/doods/faster_rcnn_inception_v2_coco_2018_01_28.pb
    labelFile: /share/doods/coco_labels1.txt
    numThreads: 1
    numConcurrent: 1
    hwAccel: false

Don’t know if it matters or not. Just noticed it.

Wow this is an awesome add-on, it works so well, is it possible to use it for OCR?

interesting!! what type of detector was that? tensorflow or tflite? tensorflow can not go that wrong so must be tflite. right?

Tensorflow can most definitely go that wrong!
In the last week I’ve had a deer be identified as a person and a reflection that looks like a wavy horizontal line of fog. A while ago a bird flew in close to my cam and the snapshot caught it with wings open and it said person.

Did anyone tried using any of mobilenet_v2 models with success? I can’t get them working.
Inception model is too heavy for my current setup while coco_ssd_mobilenet_v1_1.0_quant_2018_06_29 seems to be a little bit too inaccurate. So I’m looking for something a little more accurate.

{
      "name": "inception",
      "type": "tensorflow",
      "modelFile": "/share/doods/faster_rcnn_inception_v2_coco_2018_01_28.pb",
      "labelFile": "/share/doods/coco_labels1.txt",
      "numThreads": 1,
      "numConcurrent": 1,
      "hwAccel": false

Thank you, super easy to switch from Tensorflow component. Your work is appreciated.

Did you find any improvements in speed when scanning the snapshots instead of the stream? I’ve been pretty pleased with it not missing people on my main front cameras but I still store snapshots of all motion regardless of person but only get notified when a person is detected. It would be nice to shave a second or two off the response time