HumanSignal / label-studio-converter

Tools for converting Label Studio annotations into common dataset formats
https://labelstud.io/
255 stars 132 forks source link

How to fix the order of id and name in YOLO format #104

Closed youyuge34 closed 1 year ago

youyuge34 commented 2 years ago

When export the same tags of object detection in YOLO format, the tag order of two datasets are different:

{
  "categories": [
    {
      "id": 0,
      "name": "list_describe"
    },
    {
      "id": 1,
      "name": "discount"
    },
    {
      "id": 2,
      "name": "member"
    },
    {
      "id": 3,
      "name": "card_price"
    },
    {
      "id": 4,
      "name": "card_name"
    },
    {
      "id": 5,
      "name": "card_img"
    },
    {
      "id": 6,
      "name": "card"
    }
  ],
  "info": {
    "year": 2022,
    "version": "1.0",
    "contributor": "Label Studio"
  }
}
{
  "categories": [
    {
      "id": 0,
      "name": "card_img"
    },
    {
      "id": 1,
      "name": "card_name"
    },
    {
      "id": 2,
      "name": "card_price"
    },
    {
      "id": 3,
      "name": "card"
    },
    {
      "id": 4,
      "name": "member"
    },
    {
      "id": 5,
      "name": "discount"
    },
    {
      "id": 6,
      "name": "list_describe"
    }
  ],
  "info": {
    "year": 2022,
    "version": "1.0",
    "contributor": "Label Studio"
  }
}

What is the logic of the name order and how to fix the order between two Projects?

youyuge34 commented 2 years ago

Why they are not in alphabetical order?

KonstantinKorotaev commented 2 years ago

@youyuge34 Hi, could you please share your label config?

youyuge34 commented 2 years ago

@KonstantinKorotaev

<View>
  <View style="display:flex;align-items:start;gap:8px;flex-direction:column-reverse">
    <Image name="image" value="$url" zoom="true" zoomControl="true" width="400px"/>
    <RectangleLabels name="label" toName="image" showInline="true">
      <Label value="card" background="#FFA39E"/>
      <Label value="card_img" background="#0d25d3"/>
      <Label value="card_name" background="#FFC069"/>
      <Label value="card_price" background="#03ad00"/>
      <Label value="member" background="#ec0f04"/>
      <Label value="discount" background="#f0cc19"/>
      <Label value="list_describe" background="#da1fff"/>
    </RectangleLabels>
  </View>
</View>
KonstantinKorotaev commented 2 years ago

@youyuge34 Could you please also share your version of label-studio-converter?

youyuge34 commented 2 years ago

@KonstantinKorotaev I use label-studio v1.4 and label-studio-converter 0.0.36

KonstantinKorotaev commented 2 years ago

label-studio-converter 0.0.36

Could you please update it to 0.0.40 and check one more time?

shafeeq07 commented 1 year ago

Hi, I'm facing the same issue. I think it is because set() is used to filter duplicate elements in labels list, but set() does not maintain order of the elements so it changes the tag order.

here is the line reference https://github.com/heartexlabs/label-studio-converter/blob/7918410c420d6ffe00991409db96798b6a610293/label_studio_converter/converter.py#L911

KonstantinKorotaev commented 1 year ago

Hi @shafeeq07 Could you please share your label config?

TrueWodzu commented 1 year ago

Hi, I have the same problem. Latest label studio version used. After exporting my project to YOLOv5 the class order is like this:

head person

but I want to have it defined like this: person head

it is important for transfer learning where ID of classes are already defined. I think the best solution would be to add an tag or or whatever name you chose to labelling interface.

makseq commented 1 year ago

Try adding category to labels <Label category="123">, e.g.:

<View>
  <View style="display:flex;align-items:start;gap:8px;flex-direction:column-reverse">
    <Image name="image" value="$url" zoom="true" zoomControl="true" width="400px"/>
    <RectangleLabels name="label" toName="image" showInline="true">
      <Label value="card" background="#FFA39E" category="1"/>
      <Label value="card_img" background="#0d25d3" category="2"/>
      <Label value="card_name" background="#FFC069" category="3"/>
      <Label value="card_price" background="#03ad00" category="4"/>
      <Label value="member" background="#ec0f04" category="5"/>
      <Label value="discount" background="#f0cc19" category="6"/>
      <Label value="list_describe" background="#da1fff" category="7"/>
    </RectangleLabels>
  </View>
</View>

How it works: https://github.com/heartexlabs/label-studio-converter/pull/50/files#diff-322ce95b5aa5f02fb330c7f62be1ea0066c01829b564db0644872e09338a3ddfR745