roflcoopter / viseron

Self-hosted, local only NVR and AI Computer Vision software. With features such as object detection, motion detection, face recognition and more, it gives you the power to keep an eye on your home, office or any other place you want to monitor.
MIT License
1.7k stars 176 forks source link

Support Coral on NUC #11

Closed alexandrepossebom closed 4 years ago

alexandrepossebom commented 4 years ago

I am trying to take a look at you software but I have a problema with NUC and Coral.

My config:


# See the README for the full list of configuration options.
cameras:
  - name: Backyard
    host: 192.168.1.50
    port: 554
    username: admin
    password: foobar
    path: /cam/realmonitor?channel=4&subtype=0
    motion_detection:
      interval: 1
      trigger: true
    object_detection:
      type: edgetpu
      interval: 1
      labels:
        - label: person
          confidence: 0.9
        - label: dog
          confidence: 0.9
        - label: car
          confidence: 0.9

# MQTT is optional
mqtt:
 broker: 192.168.1.100
 port: 1883
 username: mqtt
 password: foobar

logging:
  level: debug

I am giving this error:

Traceback (most recent call last):
  File "viseron.py", line 7, in <module>
    from lib.config import ViseronConfig
  File "/src/viseron/lib/config/__init__.py", line 118, in <module>
    VALIDATED_CONFIG = VISERON_CONFIG_SCHEMA(raw_config)
  File "/usr/local/lib/python3.6/dist-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.6/dist-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.6/dist-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: extra keys not allowed @ data['cameras'][0]['object_detection']['type']

I am running docker using this cmd line :

# docker run --rm -v /usr/share/hassio/share/viseron/recordings:/recordings -v /usr/share/hassio/share/viseron/config:/config -v /etc/localtime:/etc/localtime:ro -v /dev/bus/usb:/dev/bus/usb --privileged --name viseron --device /dev/dri roflcoopter/viseron:latest

Thank you in advanced.

roflcoopter commented 4 years ago

Thanks for showing interest in the project and also for the great issue report!

type is not allowed to be specified under the object_detection block for a camera. It should be specified in the global domain, so your config needs to be like this:

# See the README for the full list of configuration options.
cameras:
  - name: Backyard
    host: 192.168.1.50
    port: 554
    username: admin
    password: foobar
    path: /cam/realmonitor?channel=4&subtype=0
    motion_detection:
      interval: 1
      trigger: true
    object_detection:
      interval: 1
      labels:
        - label: person
          confidence: 0.9
        - label: dog
          confidence: 0.9
        - label: car
          confidence: 0.9

# MQTT is optional
mqtt:
 broker: 192.168.1.100
 port: 1883
 username: mqtt
 password: foobar

object_detection:
  type: edgetpu

logging:
  level: debug

Let me know if this works out for you. Edit: you can see how the camera object detection and global object detection config differs in the readme

alexandrepossebom commented 4 years ago

Thank you @roflcoopter for your answer and sorry for my mistake.

Anyway I think x86 dockers machine doesn't have tensor flow.

Look my error now:

[2020-09-10 08:17:04] [lib.detector            ] [INFO    ] - Initializing detection thread
Traceback (most recent call last):
  File "viseron.py", line 163, in <module>
    main()
  File "viseron.py", line 43, in main
    detector = Detector(config)
  File "/src/viseron/lib/detector.py", line 20, in __init__
    from lib.edgetpu_detection import ObjectDetection
  File "/src/viseron/lib/edgetpu_detection.py", line 4, in <module>
    import tflite_runtime.interpreter as tflite
ModuleNotFoundError: No module named 'tflite_runtime'
roflcoopter commented 4 years ago

Ahh i see what the error is. can you run this for me and see if it works? docker exec -it viseron bash pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl

If it does i will add it to the image

alexandrepossebom commented 4 years ago
ERROR: tflite_runtime-2.1.0.post1-cp37-cp37m-linux_x86_64.whl is not a supported wheel on this platform.
roflcoopter commented 4 years ago

Hmm what kind of machine are you running on?

alexandrepossebom commented 4 years ago

It's a Intel NUC i3

roflcoopter commented 4 years ago

Okey now i get it, the base ubuntu image contains python 3.6 so this would be the correct one. docker exec -it viseron bash pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp36-cp36m-linux_x86_64.whl

alexandrepossebom commented 4 years ago

Now it's works thank you!

but:

[2020-09-10 11:25:29] [lib.detector            ] [INFO    ] - Initializing detection thread
Traceback (most recent call last):
  File "viseron.py", line 163, in <module>
    main()
  File "viseron.py", line 43, in main
    detector = Detector(config)
  File "/src/viseron/lib/detector.py", line 24, in __init__
    label_path=self.config.object_detection.label_path,
  File "/src/viseron/lib/edgetpu_detection.py", line 13, in __init__
    self.labels = self.read_labels(label_path)
  File "/src/viseron/lib/edgetpu_detection.py", line 42, in read_labels
    labels[int(pair[0])] = pair[1].strip()
IndexError: list index out of range
mario-tux commented 4 years ago

it looks that the edgetpu labels file is not present in the docker image for NUC. I got a i3 NUC with Coral too.

roflcoopter commented 4 years ago

the labels file should be in the container under /detectors/models/edgetpu/labels.txt so you need to update your object detection config to this:

object_detection:
  type: edgetpu
  model_path: /detectors/models/edgetpu/model.tflite
  label_path: /detectors/models/edgetpu/labels.txt

The default config isnt smart enough yet to figure out where the model/label file is if you deviate from the default which is darknet. I will remedy this in the future

alexandrepossebom commented 4 years ago

Thank you @roflcoopter now it's works.

roflcoopter commented 4 years ago

Great! Closing. Feel free to reopen this or a new issue if you are having trouble

mario-tux commented 4 years ago

it looks that the edgetpu labels file is not present in the docker image for NUC. I got a i3 NUC with Coral too.

I was missing such file because I was using the roflcoopter/viseron-vaapi:latest image.

How should I make sure that ffmpeg is using vaapi in the decoding of the h264 image?

UPDATE It looks, in order to make it works, it is enough to add to each camera the parameters:

hwaccel_args:
    - -hwaccel
    - vaapi
    - -hwaccel_device
    - /dev/dri/renderD128
    - -hwaccel_output_format
    - yuv420p

I'm a bit confused by the docker images distinction: the use of vaapi for decoding jointly to Coral EdgeTPU for detection doesn't look to be covered. Furthermore when I tried to use the viseron-vaapi image, I got a message saying that OpenCV was not able to use my GPU for detection.

roflcoopter commented 4 years ago

I will fix so EdgeTPU is fully installed in the VAAPI image, along with models etc. When you run the VAAPI image, it will automatically genereate the proper hwaccel arguments for ffmpeg.

What does your docker run command look like? And what processor do you use?

mario-tux commented 4 years ago

What does your docker run command look like?

I use docker compose (inside Portainer):

  viseron:
    container_name: viseron
    restart: unless-stopped
    network_mode: bridge
    privileged: true
    #image: roflcoopter/viseron-vaapi:latest
    image: roflcoopter/viseron:latest
    devices:
      - /dev/dri:/dev/dri
    volumes:
      - /dev/bus/usb:/dev/bus/usb
      - /etc/localtime:/etc/localtime:ro
      - /srv/docker/viseron/data:/config
      - /mnt/cctv/viseron:/recordings

And what processor do you use?

My /proc/cpuinfo says Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz.

roflcoopter commented 4 years ago

if you turn on debug logging for the camera, what does the default ffmpeg command look like?

mario-tux commented 4 years ago

if you turn on debug logging for the camera, what does the default ffmpeg command look like?

Indeed, it looks that the viseron container activate by default the vaapi con camera decoding:

[2020-09-12 09:59:27] [lib.camera.camera_1     ] [DEBUG   ] - FFMPEG decoder command: ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -stimeout 5000000 -use_wallclock_as_timestamps 1 -vsync 0 -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format yuv420p -rtsp_transport tcp -i rtsp://camera-1.lan:554/h264 -f rawvideo -pix_fmt nv12 pipe:1,

So the above hwaccel_args should not be necessary, right?

roflcoopter commented 4 years ago

No it shouldnt, however it looks like you still have them in your config as -hwaccel_output_format yuv420p is not part of the default command