snowzach / doods2

API for detecting objects in images and video streams using Tensorflow
MIT License
232 stars 30 forks source link

How to add a model to TensorFlow? #44

Closed bhusain966 closed 1 year ago

bhusain966 commented 2 years ago

Greetings,

I've originally posted this on self-hosted subreddit and it was really helpful to get me started.

My youngest son has Autism Spectrum Disorder (ASD), he's 5 now. Recently he developed a habit of taking off his clothes and playing around without any clothes on! I already have a few cameras around the house, however, I was wondering if anyone knows a solution that can detect if my son is moving around the house without any clothes on so I can fire up automation and play a pre-recorded voice note on speakers in the house asking him to put on his clothes again!

So I've managed to get a live camera feed into Hom Assistant, using (https://github.com/snowzach/doods2) also was able to detect objects and persons using (tensorflow) and HA saves a snapshot for labels I want to capture, such as "person" or "people". Seems to be working just fine.

I was looking for some pre-trained models to detect nudity / NSFW and found some such as: https://github.com/minto5050/NSFW-detection. However, I couldn't manage to upload this model and run it for some reason. I've downloaded the model and labels files and placed them in the models and declared it in the config file but it isn't working.

Here is how config.yaml lookslike:


doods:
  log: detections
  boxes:
    enabled: True
    boxColor: [0, 255, 0]
    boxThickness: 1
    fontScale: 1.2
    fontColor: [0, 255, 0]
    fontThickness: 1
  regions:
    enabled: True
    boxColor: [255, 0, 255]
    boxThickness: 1
    fontScale: 1.2
    fontColor: [255, 0, 255]
    fontThickness: 1
  globals:
    enabled: True
    fontScale: 1.2
    fontColor: [255, 255, 0]
    fontThickness: 1
  detectors:
    - name: default
      type: tflite
      modelFile: models/coco_ssd_mobilenet_v1_1.0_quant.tflite
      labelFile: models/coco_labels0.txt

    - name: tensorflow
      type: tensorflow
      modelFile: models/faster_rcnn_inception_v2_coco_2018_01_28.pb
      labelFile: models/coco_labels1.txt

    - name: nsfws
      type: tensorflow
      modelFile: models/NSFW.tflite
      labelFile: models/dict.txt

    - name: pytorch
      type: pytorch
      modelFile: ultralytics/yolov5,yolov5s
mqtt:
  metrics: true
  broker:
    host: "mqttBroker"
    #port: 1883
    #user: "username"
    #password: "password"
  requests:
    - id: firstrequest
      detector_name: default
      preprocess: []
      separate_detections: false
      crop: false
      binary_images: false
      detect:
        "*": 50
      regions:
      - top: 0.1
        left: 0.1
        bottom: 0.9
        right: 0.9
        detect:
          "*": 50
        covers: false
      data: rtsp://192.168.2.231/ch0_0.h264 

After restarting the container, I get this in the log:

2022-05-15 16:08:19,836 - doods.doods - INFO - Registered detector type:tflite name:default
2022-05-15 16:08:21,966 - doods.doods - INFO - Registered detector type:tensorflow name:tensorflow
2022-05-15 16:08:21,967 - doods.doods - ERROR - Could not create detector tensorflow/nsfws: Error parsing message with type 'tensorflow.GraphDef'
Using cache found in /root/.cache/torch/hub/ultralytics_yolov5_master
YOLOv5 🚀 2022-5-10 torch 1.10.2+cu102 CPU

Fusing layers... 
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients
Adding AutoShape... 
2022-05-15 16:08:24,158 - doods.doods - INFO - Registered detector type:pytorch name:pytorch
2022-05-15 16:08:24,208 - uvicorn.error - INFO - Started server process [1]
2022-05-15 16:08:24,208 - uvicorn.error - INFO - Waiting for application startup.
2022-05-15 16:08:24,208 - uvicorn.error - INFO - Application startup complete.
2022-05-15 16:08:24,209 - uvicorn.error - INFO - Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
GitHub Discord Credits

Only NSFW detector is giving error.

Any thoughts on how can I make this model or any other similar model work for my purpose above?

Thanks and much appreciated.

snowzach commented 2 years ago

I tried a handful of models but none of them worked with doods. Basically a bunch of them require customization of code that's not really what's typical of object detection models. Apparently this guy uses some microsoft adapter. This seemed most promising but it's going to take a bit more work to be able to leverage in doods. https://praneethbedapudi.medium.com/nudenet-an-ensemble-of-neural-nets-for-nudity-detection-and-censoring-c8fcefa6cc92

Sorry, this is a clever way to solve the problem. I'm a bit buried but if I can get some time I can try to add the microsoft library at some point.

bhusain966 commented 2 years ago

Thanks Zack.

Yea I’ve been playing around with Nudenet but since I am not very much familiar with python or coding I keep getting some errors during the process which I can’t figure out how to solve.

I was able to try and load different models using DeepStack with home assistant, but couldn’t find any pre trained model for DeepStack that I can use.

Thanks again for your great work on doods it’s really cool!

Best

Sent from my iPhone

On 16 May 2022, at 5:43 AM, Zach @.***> wrote:

 I tried a handful of models but none of them worked with doods. Basically a bunch of them require customization of code that's not really what's typical of object detection models. Apparently this guy uses some microsoft adapter. This seemed most promising but it's going to take a bit more work to be able to leverage in doods. https://praneethbedapudi.medium.com/nudenet-an-ensemble-of-neural-nets-for-nudity-detection-and-censoring-c8fcefa6cc92

Sorry, this is a clever way to solve the problem. I'm a bit buried but if I can get some time I can try to add the microsoft library at some point.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

Curid commented 2 years ago

I tried a handful of models but none of them worked with doods. Basically a bunch of them require customization of code that's not really what's typical of object detection models.

I thought they used image classification.