notAI-tech / NudeNet

Lightweight nudity detection
https://nudenet.notai.tech/
GNU Affero General Public License v3.0
1.76k stars 342 forks source link

docker service needs to return json in more parseable format #64

Closed vimagick closed 3 years ago

vimagick commented 3 years ago

Hi developers: Thank you for this great project!

$ docker run -d -p 8080:8080 notaitech/nudenet:detector

$ cat data.json
{
  "data": {
    "image.jpg": "<--base64-of-image-->"
  }
}

$ curl -H content-type:application/json http://localhost:8080/sync -d @data.json
{
  "prediction": "{'image.jpg': [{'box': [130, 89, 250, 209], 'score': 0.96751046, 'label': 'FACE_F'}, {'box': [98, 511, 281, 710], 'score': 0.9542637, 'label': 'EXPOSED_BELLY'}, {'box': [75, 356, 191, 474], 'score': 0.90151, 'label': 'EXPOSED_BREAST_F'}, {'box': [201, 357, 315, 474], 'score': 0.89977014, 'label': 'EXPOSED_BREAST_F'}, {'box': [146, 770, 246, 867], 'score': 0.85078907, 'label': 'COVERED_GENITALIA_F'}, {'box': [302, 348, 343, 411], 'score': 0.73944795, 'label': 'EXPOSED_ARMPITS'}, {'box': [52, 349, 91, 410], 'score': 0.703932, 'label': 'EXPOSED_ARMPITS'}]}",
  "success": true
}

Is it possible to return json in another format? It'll easy to parse. :)

{
  "prediction": {
    "image.jpg": [
      {
        "box": [
          130,
          89,
          250,
          209
        ],
        "score": 0.96751046,
        "label": "FACE_F"
      },
      {
        "box": [
          98,
          511,
          281,
          710
        ],
        "score": 0.9542637,
        "label": "EXPOSED_BELLY"
      },
      {
        "box": [
          75,
          356,
          191,
          474
        ],
        "score": 0.90151,
        "label": "EXPOSED_BREAST_F"
      },
      {
        "box": [
          201,
          357,
          315,
          474
        ],
        "score": 0.89977014,
        "label": "EXPOSED_BREAST_F"
      },
      {
        "box": [
          146,
          770,
          246,
          867
        ],
        "score": 0.85078907,
        "label": "COVERED_GENITALIA_F"
      },
      {
        "box": [
          302,
          348,
          343,
          411
        ],
        "score": 0.73944795,
        "label": "EXPOSED_ARMPITS"
      },
      {
        "box": [
          52,
          349,
          91,
          410
        ],
        "score": 0.703932,
        "label": "EXPOSED_ARMPITS"
      }
    ]
  },
  "success": true
}
bedapudi6788 commented 3 years ago

@vimagick I didn't completely understand this. Can you explain a little bit about what you mean by parsing the json? In which language are you trying to parse the returned json?

vimagick commented 3 years ago

I'm trying to extract data from the json in bash (with jq).

For example:

$ jq '.prediction["image.jpg"][].label' output.json
"FACE_F"
"EXPOSED_BELLY"
"EXPOSED_BREAST_F"
"EXPOSED_BREAST_F"
"COVERED_GENITALIA_F"
"EXPOSED_ARMPITS"
"EXPOSED_ARMPITS"
bedapudi6788 commented 3 years ago

I don't think I will be able to help that much here. The docker service is made using fastDeploy (https://github.com/notAI-tech/fastDeploy), for which we have a standardized response format.