-
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
Conversation
fastlabel/converters.py
Outdated
| for index, keypoint_key in enumerate(keypoint_keys): | ||
| keypoint_value = keypoint_values[index] | ||
| if keypoint_value == [0,0,0]: | ||
| raise FastLabelInvalidException(f"Keypoint value is [0,0,0]. annotationId: {target_coco_annotation['id']}", 422) |
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.
[0,0,0]のときは、そのキーポイントはないということはなので、姿勢推定として抜けているキーポイントがあるということなのでエラーにしています!
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.
[0,0,0]
これって1つ目が0で2つ目も0は座標としてはありうると思うから、配列の3つ目が0だけじゃなくて、1か2以外でも問題があるかと思うけど [0,0,0]にしてる理由ある?
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.
annotationId はスネークケースで
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.
これって1つ目が0で2つ目も0は座標としてはありうると思うから、配列の3つ目が0だけじゃなくて、1か2以外でも問題があるかと思うけど [0,0,0]にしてる理由ある?
ここ漏れてる?
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.
| # Convert to Fastlabel | ||
|
|
||
| def convert_coco_to_fastlabel(self, file_path: str) -> dict: | ||
| def convert_coco_to_fastlabel(self, file_path: str, annotation_type: str) -> dict: |
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のファイルの中に姿勢推定のデータ化を見分けるフラグがなかったので、アノテーションタイプを入力するようにしています
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.
了解!
fastlabel/__init__.py
Outdated
| with open(file_path, "r") as f: | ||
| file = f.read() | ||
| return converters.execute_coco_to_fastlabel(eval(file)) | ||
| return converters.execute_coco_to_fastlabel(eval(file.replace("false","False").replace("true","True")), annotation_type) |
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.
これはなんで、replaceしてるん?
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に書かれているfalseが、pythonのFalse(最初文字であるFが大文字)と互換性がなくてエラーが出ているようでした。
Traceback (most recent call last):
File "/Users/tamenishitakahiro/fastlabelProject/fastlabel-python-sdk/examples/convert_coco_to_fastlabel.py", line 18, in <module>
annotations_map = client.convert_coco_to_fastlabel(file_path=input_file_path,annotation_type="polygon")
File "/Users/tamenishitakahiro/.pyenv/versions/3.9.10/lib/python3.9/site-packages/fastlabel/__init__.py", line 1617, in convert_coco_to_fastlabel
return converters.execute_coco_to_fastlabel(eval(file), annotation_type)
File "<string>", line 11, in <module>
NameError: name 'false' is not defined
お客さんからもらったファイル
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.
fca4ae8
もし、画像のファイル名などにfalse やtrueが入っていたら危険なので修正しました!
evalは調べた感じいらないと判断しましたが、もし必要なようでしたら教えて下さい。
fastlabel/converters.py
Outdated
| "type": annotation_type, | ||
| } | ||
| ) | ||
| if annotation_type in ["bbox", "polygon"]: |
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.
AnnotationType を使ってもらえると!
fastlabel/converters.py
Outdated
| "type": annotation_type, | ||
| } | ||
| ) | ||
| elif annotation_type == "pose_estimation": |
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.
ここもAnnotationType を使ってもらえると!
| keypoints = [] | ||
| target_coco_annotation_keypoints = target_coco_annotation["keypoints"] | ||
| keypoint_keys = coco_categories_keypoints[target_coco_annotation["category_id"]] | ||
| keypoint_values = [target_coco_annotation_keypoints[i:i + 3] for i in range(0, len(target_coco_annotation_keypoints), 3)] |
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.
3つずつ配列にしてるんだと思うけどわかりにくいので、
処理前と処理後の配列とかを例にコメント追加しておいてもらえると!
|
@qoone |
fastlabel/converters.py
Outdated
| keypoint_values = [target_coco_annotation_keypoints[i:i + 3] for i in range(0, len(target_coco_annotation_keypoints), 3)] | ||
| for index, keypoint_key in enumerate(keypoint_keys): | ||
| keypoint_value = keypoint_values[index] | ||
| if keypoint_value[2] == 0: |
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.
ここって1と2以外じゃない?
fastlabel/converters.py
Outdated
| for index, keypoint_key in enumerate(keypoint_keys): | ||
| keypoint_value = keypoint_values[index] | ||
| if keypoint_value[2] == 0: | ||
| raise FastLabelInvalidException(f"Keypoint value is [0,0,0]. annotation_id: {target_coco_annotation['id']}", 422) |
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.
条件とメッセージの内容がずれてない?
| 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) |
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.
・"Visibility flagが0の場合はキーポイントがないのでスキップにする。
↓
・"Visibility flagが1,2以外の場合は、バリデーションエラーにする
|
@qoone |
概要
アプリケーション側プルリク
https://github.com/fastlabel/fastlabel-application/pull/2264
COCO形式の姿勢推定のデータをfastlabel形式に変換する。
また、そのインポートをする
実装が確定次第、readmeを書きます!
画面
テスト
補足