scalabel / scalabel

Scalabel: A versatile web-based visual data annotation tool
https://www.scalabel.ai
Apache License 2.0
595 stars 121 forks source link

Error when trying to convert to COCO: ValueError: Image shape not defined! #518

Closed lewisd1996 closed 1 year ago

lewisd1996 commented 1 year ago

Describe the bug When running the command, I get the following error:

python3 -m scalabel.label.to_coco -i /Users/me/Desktop/scalabel/cards_export_2023-06-16_11-29-52.json -o /Users/me/Desktop/scalabel/CONVERTED_cards_export_2023-06-16_11-29-52.json  -m det
...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/me/Desktop/scalabel/scalabel/label/to_coco.py", line 551, in <module>
    run(parse_arguments())
  File "/Users/me/Desktop/scalabel/scalabel/label/to_coco.py", line 543, in run
    coco = convert_func(frames, config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Desktop/scalabel/scalabel/label/to_coco.py", line 160, in scalabel2coco_detection
    raise ValueError("Image shape not defined!")
ValueError: Image shape not defined!

Expected behavior To convert the file to COCO.

Desktop (please complete the following information):

Additional context A sample of one of my frames:

{
      "name": "https://drive.google.com/uc?id=1cADmglXqXJaWwQV_yUVkQgH80B9CmcZC7&export=download",
      "url": "https://drive.google.com/uc?id=1cADmglXqXJaWQwV_yUVkQgH80B9CmcZC7&export=download",
      "videoName": "",
      "timestamp": 0,
      "attributes": {},
      "labels": [
        {
          "id": "ELMO3PWaUkaS37TS",
          "category": "card",
          "attributes": {},
          "manualShape": true,
          "poly2d": [
            {
              "vertices": [
                [
                  58.99953467868338,
                  36.70062695924765
                ],
                [
                  71.58260677899686,
                  298.84796238244513
                ],
                [
                  255.08574157523512,
                  293.6050156739812
                ],
                [
                  247.74561618338558,
                  28.311912225705328
                ]
              ],
              "types": "LLLL",
              "closed": true
            }
          ],
          "box2d": null,
          "box3d": null
        },
        {
          "id": "CSHpAG4LXUiIKmaE",
          "category": "card",
          "attributes": {},
          "manualShape": true,
          "poly2d": [
            {
              "vertices": [
                [
                  293.88354721786834,
                  28.311912225705328
                ],
                [
                  291.78636853448273,
                  291.5078369905956
                ],
                [
                  481.5810393808777,
                  296.7507836990596
                ],
                [
                  486.8239860893417,
                  31.4576802507837
                ]
              ],
              "types": "LLLL",
              "closed": true
            }
          ],
          "box2d": null,
          "box3d": null
        },
        {
          "id": "WYecjE2JGOjpscWS",
          "category": "card",
          "attributes": {},
          "manualShape": true,
          "poly2d": [
            {
              "vertices": [
                [
                  523.5246130485893,
                  34.60344827586207
                ],
                [
                  523.5246130485893,
                  298.84796238244513
                ],
                [
                  721.7079986285266,
                  299.8965517241379
                ],
                [
                  719.6108199451411,
                  27.26332288401254
                ]
              ],
              "types": "LLLL",
              "closed": true
            }
          ],
          "box2d": null,
          "box3d": null
        },
        {
          "id": "ABCBTcWwqQ9FHyQk",
          "category": "card",
          "attributes": {},
          "manualShape": true,
          "poly2d": [
            {
              "vertices": [
                [
                  775.1860550548589,
                  12.58307210031348
                ],
                [
                  762.6029829545455,
                  281.0219435736677
                ],
                [
                  956.5920111677116,
                  289.41065830721004
                ],
                [
                  958.6891898510971,
                  19.92319749216301
                ]
              ],
              "types": "LLLL",
              "closed": true
            }
          ],
          "box2d": null,
          "box3d": null
        },
        {
          "id": "a7Qrj19QHrDAkJpu",
          "category": "card",
          "attributes": {},
          "manualShape": true,
          "poly2d": [
            {
              "vertices": [
                [
                  232.01677605799372,
                  347.0830721003135
                ],
                [
                  226.7738293495298,
                  602.9388714733542
                ],
                [
                  419.7142682210031,
                  609.230407523511
                ],
                [
                  423.9086255877743,
                  349.1802507836991
                ]
              ],
              "types": "LLLL",
              "closed": true
            }
          ],
          "box2d": null,
          "box3d": null
        },
        {
          "id": "GGZ99eqEOmUvHtQd",
          "category": "card",
          "attributes": {},
          "manualShape": true,
          "poly2d": [
            {
              "vertices": [
                [
                  457.46348452194354,
                  352.3260188087774
                ],
                [
                  464.8036099137931,
                  615.5219435736677
                ],
                [
                  653.5496914184953,
                  619.7163009404388
                ],
                [
                  653.5496914184953,
                  352.3260188087774
                ]
              ],
              "types": "LLLL",
              "closed": true
            }
          ],
          "box2d": null,
          "box3d": null
        },
        {
          "id": "wFPUQq0HklH3Q8ip",
          "category": "card",
          "attributes": {},
          "manualShape": true,
          "poly2d": [
            {
              "vertices": [
                [
                  692.3474970611285,
                  367.0062695924765
                ],
                [
                  691.2989077194358,
                  631.2507836990595
                ],
                [
                  887.6388832287047,
                  639.4436268648816
                ],
                [
                  883.3546533247351,
                  366.6809896454827
                ]
              ],
              "types": "LLLL",
              "closed": true
            }
          ],
          "box2d": null,
          "box3d": null
        }
      ],
      "sensor": -1
    },

my config:

  "config": {
    "attributes": [],
    "categories": [
      {
        "name": "card"
      }
    ]
  }
thomasehuang commented 1 year ago

The size of the image is required for the conversion to COCO, which you can either set in the config https://github.com/scalabel/scalabel/blob/master/scalabel/label/typing.py#L172 (same for all frames) or at each frame https://github.com/scalabel/scalabel/blob/master/scalabel/label/typing.py#L135.

lewisd1996 commented 1 year ago

Makes sense thank you @thomasehuang

Is there any sort of tools or methods that will resize all the images for me within scalabel or is this something that should have been done before I tagged my images?

Apologies, still a beginner

thomasehuang commented 1 year ago

You don't need to resize the images, you just need to determine the size of your images and set that in the file. For example, if your image has height 720 pixels and width 1280 pixels, you can add ImageSize(height=720, width=1280) to the config. Something like:

  "config": {
    "attributes": [],
    "categories": [
      {
        "name": "card"
      }
    ],
    "imageSize": {"height": 720, "width": 1280}
  }

This is needed since the COCO format needs the image dimensions in the annotations file. Hope that makes sense.

lewisd1996 commented 1 year ago

@thomasehuang awesome makes sense, thank you!