# Converter - COCO to LS

**URL:** <https://community.labelstud.io/t/converter-coco-to-ls/647>\
**Category:** Label Studio Support\
**Tags:** annotations\
**Created:** [October 23, 2025, 8:50pm UTC](https://community.labelstud.io/t/converter-coco-to-ls/647 "2025-10-23T20:50:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![awasson](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/awasson/32/458_2.png) [@awasson](https://community.labelstud.io/u/awasson)\
**Post date:** [October 23, 2025, 8:50pm UTC](https://community.labelstud.io/t/converter-coco-to-ls/647/1 "2025-10-23T20:50:51Z")

</div>

Im in the process of trying to convert the COCO dataset into something Label-Studio can understand, and checked around before asking. I stumbled across [someone else doing it](https://community.labelstud.io/t/how-do-i-upload-annotations-in-the-ms-coco-format-for-images/374), and they seemed to be able to get it to work, but nothing is being outputted for me.

```bash
label-studio-converter import coco -i /orin-robotics/datasets/coco/annotations/instances_val2017.json -o /orin-robotics/coco.json

```

It’s throwing a JSON key error on the annotations file, and Im wondering if Im using the right file for the conversion.

`File “/root/Documents/label-studio/lib/python3.12/site-packages/label_studio_converter/imports/coco.py”, line 54, in create_segmentation`  
`segmentation = annotation[‘segmentation’][0]`

All of the data was pulled from the [COCO](https://cocodataset.org/#download) site

---

<div class="post-metadata">

**Author:** ![makseq](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/makseq/32/26_2.png) [@makseq](https://community.labelstud.io/u/makseq)\
**Post date:** [January 16, 2026, 10:39pm UTC](https://community.labelstud.io/t/converter-coco-to-ls/647/2 "2026-01-16T22:39:58Z")

</div>

Hello, I apologize for the long answer.

* * *

**Why you’re seeing `segmentation = annotation['segmentation'][0]` fail**  
That traceback means the converter is iterating over COCO `annotations`, sees a `"segmentation"` field, and assumes it’s a _polygon list_ (`[[x1,y1,x2,y2,...], ...]`). But in COCO, segmentation can be either:

- _Polygons_ (list of lists), or
- _RLE masks_ (a dict, commonly when `iscrowd=1`)

In the converter code, RLE is detected when `annotation.get("iscrowd") == 1`, and it explicitly logs that _RLE is not supported_ for COCO import into Label Studio: the code flags RLE and prints an error (`"RLE in segmentation is not yet supported in COCO"`) while iterating annotations.  
Source: [label-studio-sdk converter COCO import code](https://github.com/HumanSignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/imports/coco.py#L269-L276)

This matches what people hit in the field: COCO mixes polygon + RLE segmentations, and the converter only handles polygon segmentation reliably; when it hits RLE/different shapes, you can get failures like `KeyError: 0` / indexing errors.  
Source: [GitHub issue #8707](https://github.com/HumanSignal/label-studio/issues/8707)

**Are you using the right COCO file?**  
Yes: `instances_val2017.json` is the right _type_ of COCO file for object detection/segmentation import.

But if you instead try files like `captions_train2017.json`, those aren’t instance annotations and won’t have `categories`/`annotations` in the expected structure—leading to errors like `KeyError: 'categories'`.  
Source: [GitHub issue #8707](https://github.com/HumanSignal/label-studio/issues/8707)

**What to do next (practical paths)**

_1) If you only need bounding boxes (YOLO training, etc.)_  
Avoid segmentation conversion entirely: create a COCO file that includes only `bbox` annotations (or ignore segmentation), then import. The converter supports bbox conversion via `create_bbox(...)`.  
You can also keep only annotations where `"bbox"` exists and drop `"segmentation"` to avoid hitting the segmentation path. (You’d do this with a small preprocessing script.)

> This is usually the simplest if your goal is “get COCO into LS to edit boxes”.

_2) If you need segmentations, you must avoid RLE entries_  
Filter your COCO annotations to only polygon segmentations:

- Keep only annotations where `iscrowd == 0` (polygon segmentations are generally there; RLE often correlates with `iscrowd==1`)
- And ensure `annotation["segmentation"]` is a non-empty list of lists

The failure you saw (`annotation['segmentation'][0]`) is exactly what happens when `segmentation` is not a list (RLE dict) or is empty.

This is consistent with another common failure mode when segmentation lists are empty.  
Source: [GitHub issue #5898](https://github.com/HumanSignal/label-studio/issues/5898)

_3) If your source is RLE masks, use LS “Brush” RLE workflows instead of COCO-import_  
Label Studio supports importing brush segmentation pre-annotations in RLE format via predictions workflows (this is often the correct route for mask datasets), as referenced in the support reply for the same problem.  
Source: [GitHub issue #8707](https://github.com/HumanSignal/label-studio/issues/8707#issuecomment-3463834667)

**Two quick clarifying questions**

1. Do you actually need _segmentations_, or are _bounding boxes_ enough for your workflow?
2. Can you paste _one failing annotation object_ (the JSON for a single entry in `annotations[]` where it crashes), especially its `segmentation` and `iscrowd` fields?  
With that, I can tell you exactly which filtering/preprocess rule will fix your dataset.

_Further information:_

- COCO import converter logic (RLE detection via `iscrowd`): [label-studio-sdk `imports/coco.py` lines 269-276](https://github.com/HumanSignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/imports/coco.py#L269-L276)
- Field report of the same failure mode + explanation (polygon vs RLE, `categories` missing in captions file): [Label Studio GitHub issue #8707](https://github.com/HumanSignal/label-studio/issues/8707)
- Failure mode when COCO segmentation lists are empty (similar indexing error): [Label Studio GitHub issue #5898](https://github.com/HumanSignal/label-studio/issues/5898)
