tnc-ca-geo / animl-ml

Machine Learning resources for camera trap data processing
Other
4 stars 1 forks source link

Remove annotations with negative bounding box values during data cleaning #122

Open nathanielrindlaub opened 4 months ago

nathanielrindlaub commented 4 months ago

Add to clean_cct() function in clean_and_combine_datasets.ipynb. Evidently the Animl frontend is capable of creating bounding boxes in which the xmax is smaller than the xmin, which will produce negative absolute pixel values when we export it to COCO for cameratraps during the relToAbs() bounding box conversion:

https://github.com/tnc-ca-geo/animl-api/blob/3051013ceca4e924d3dcf021ee73ba5baddee3a4/src/task/annotations.js#L441-L449

This was the case for image jldp:76b399ca2fa9100f581878054f55d9bd, object 65b952ec6464959953d157ad. The offending object looked like:

    {
      "bbox": [
        0.36384913133495367,
        0.9380952380952381,
        0.504875926426021,
        0.9317460317460318
      ],
      "locked": true,
      "labels": [
        {
          "type": "manual",
          "conf": 1,
          "bbox": [
            0.36384913133495367,
            0.9380952380952381,
            0.504875926426021,
            0.9317460317460318
          ],
          "validation": {
            "validated": true,
            "userId": "fionajeweler@umail.ucsb.edu",
            "_id": {
              "$oid": "65b952ef013265f8a45afc93"
            },
            "validationDate": {
              "$date": "2024-01-30T19:50:07.458Z"
            }
          },
          "userId": "fionajeweler@umail.ucsb.edu",
          "_id": {
            "$oid": "65b952ef6464959953d157ae"
          },
          "labeledDate": {
            "$date": "2024-01-30T19:50:07.458Z"
          },
          "labelId": "37d964c6-e256-49cb-bc30-ff40f1652262"
        }
      ],
      "_id": {
        "$oid": "65b952ec6464959953d157ad"
      }
    },

Which produces a COCO annotation that looks like:

        {
            "id": "65b952ec6464959953d157ad",
            "image_id": "jldp:76b399ca2fa9100f581878054f55d9bd",
            "category_id": 8,
            "sequence_level_annotation": false,
            "bbox": [
                1801,
                393,
                -12,
                152
            ]
        },