[Fix] Fix bugs in the output annotation file when `--class-id-txt` is set. (#430)

* [Fix] Fix bugs in the output annotation file when  is set.

* Update labelme2coco.py

* Update labelme2coco.py

* Improve code

Co-authored-by: HinGwenWoong <peterhuang0323@qq.com>
pull/384/head
Yijie Zheng 2023-01-06 11:41:17 +08:00 committed by GitHub
parent d8cbf216de
commit 2290713ae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -171,6 +171,13 @@ def parse_labelme_to_coco(
category_to_id = all_classes_id
categories_labels = list(all_classes_id.keys())
# add class_ids and class_names to the categories list in coco_json
for class_name, class_id in category_to_id.items():
coco_json['categories'].append({
'id': class_id,
'name': class_name
})
# filter incorrect image file
img_file_list = [
img_file for img_file in Path(image_dir).iterdir()
@ -283,7 +290,7 @@ def convert_labelme_to_coco(image_dir: str,
' words, like "1 Big house" -> "1 '
'Big-house".')
v, k = class_info
all_classes_id.update({k: v})
all_classes_id.update({k: int(v)})
else:
all_classes_id = None