-
Notifications
You must be signed in to change notification settings - Fork 4
update pose anno convert COCO to fastlabel #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7bd4655
update pose anno convert COCO to fastlabel
takahiro-tamenishi fca4ae8
fix read file
takahiro-tamenishi d8f8bad
fix annotation type
takahiro-tamenishi 8a06ef9
add readme
takahiro-tamenishi c966823
fix validation
takahiro-tamenishi fd6f97b
update validation
takahiro-tamenishi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from concurrent.futures import ThreadPoolExecutor | ||
| from curses import keyname | ||
| from datetime import datetime | ||
| from decimal import Decimal | ||
| from typing import List | ||
|
|
@@ -10,6 +11,8 @@ | |
| from fastlabel.const import AnnotationType | ||
| import os | ||
|
|
||
| from fastlabel.exceptions import FastLabelInvalidException | ||
|
|
||
| # COCO | ||
|
|
||
|
|
||
|
|
@@ -656,14 +659,16 @@ def __get_pixel_coordinates(points: List[int or float]) -> List[int]: | |
| return new_points | ||
|
|
||
|
|
||
| def execute_coco_to_fastlabel(coco: dict) -> dict: | ||
| def execute_coco_to_fastlabel(coco: dict ,annotation_type:str) -> dict: | ||
| coco_images = {} | ||
| for c in coco["images"]: | ||
| coco_images[c["id"]] = c["file_name"] | ||
|
|
||
| coco_categories = {} | ||
| coco_categories_keypoints={} | ||
| for c in coco["categories"]: | ||
| coco_categories[c["id"]] = c["name"] | ||
| coco_categories_keypoints[c["id"]] = c["keypoints"] | ||
|
|
||
| coco_annotations = coco["annotations"] | ||
|
|
||
|
|
@@ -682,19 +687,51 @@ def execute_coco_to_fastlabel(coco: dict) -> dict: | |
| if not category_name: | ||
| return | ||
|
|
||
| segmentation = target_coco_annotation["segmentation"][0] | ||
| annotation_type = "" | ||
| if len(segmentation) == 4: | ||
| annotation_type = AnnotationType.bbox.value | ||
| if len(segmentation) > 4: | ||
| annotation_type = AnnotationType.polygon.value | ||
| annotations.append( | ||
| { | ||
| "value": category_name, | ||
| "points": segmentation, | ||
| "type": annotation_type, | ||
| } | ||
| ) | ||
| if annotation_type in [AnnotationType.bbox.value, AnnotationType.polygon.value]: | ||
| segmentation = target_coco_annotation["segmentation"][0] | ||
| annotation_type = "" | ||
| if len(segmentation) == 4: | ||
| annotation_type = AnnotationType.bbox.value | ||
| if len(segmentation) > 4: | ||
| annotation_type = AnnotationType.polygon.value | ||
| annotations.append( | ||
| { | ||
| "value": category_name, | ||
| "points": segmentation, | ||
| "type": annotation_type, | ||
| } | ||
| ) | ||
| elif annotation_type == AnnotationType.pose_estimation.value: | ||
| keypoints = [] | ||
| target_coco_annotation_keypoints = target_coco_annotation["keypoints"] | ||
| keypoint_keys = coco_categories_keypoints[target_coco_annotation["category_id"]] | ||
| # coco keypoint style [100,200,1,300,400,1,500,600,2] convert to [[100,200,1],[300,400,1],[500,600,2]] | ||
| keypoint_values = [target_coco_annotation_keypoints[i:i + 3] for i in range(0, len(target_coco_annotation_keypoints), 3)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3つずつ配列にしてるんだと思うけどわかりにくいので、 |
||
| for index, keypoint_key in enumerate(keypoint_keys): | ||
| keypoint_value = keypoint_values[index] | ||
| if keypoint_value[2] == 0: | ||
| continue | ||
| if not keypoint_value[2] in [1, 2]: | ||
| raise FastLabelInvalidException(f"Visibility flag must be 0 or 1, 2 . annotation_id: {target_coco_annotation['id']}", 422) | ||
|
Comment on lines
+712
to
+715
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ・"Visibility flagが0の場合はキーポイントがないのでスキップにする。 |
||
| # fastlabel occulusion is 0 or 1 . coco occulusion is 1 or 2. | ||
| keypoint_value[2] = keypoint_value[2] - 1 | ||
| keypoints.append({ | ||
| "key": keypoint_key, | ||
| "value": keypoint_value | ||
| }) | ||
|
|
||
| annotations.append( | ||
| { | ||
| "value": category_name, | ||
| "type": annotation_type, | ||
| "keypoints": keypoints | ||
| } | ||
| ) | ||
| else: | ||
| raise FastLabelInvalidException( | ||
| "Annotation type must be bbox or polygon ,pose_estimation.", 422 | ||
| ) | ||
|
|
||
| results[coco_images[coco_image_key]] = annotations | ||
| return results | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COCO jsonのファイルの中に姿勢推定のデータ化を見分けるフラグがなかったので、アノテーションタイプを入力するようにしています
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
カテゴリーの、"keypoints" の値が空かどうかで判断できると思うけど難しい?
現状利用している人に影響が出ちゃうから、インターフェスはどうしても無理な場合以外は、極力変えないようにしたい!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qoone
このお客さんからもらったファイルを見る限りでは、セグメンテーションのプロパティに座標情報が入っているかつ、キーポイントにも座標情報が入っていたので、このファイルを見る限りでは、一つのCOCOのファイルに矩形(多角形)とキーポイントの両方の情報が入れられると認識してます。
お客さんからもらったファイル
https://drive.google.com/file/d/1rXWrO31eYFx9l4v-uU-UmnO1XHdCtfqx/view?usp=sharing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
了解!