Skip to content

Conversation

@takahiro-tamenishi
Copy link
Contributor

概要

アプリケーション側プルリク
https://github.com/fastlabel/fastlabel-application/pull/2264

COCO形式の姿勢推定のデータをfastlabel形式に変換する。
また、そのインポートをする

実装が確定次第、readmeを書きます!

画面

テスト

補足

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0,0,0]のときは、そのキーポイントはないということはなので、姿勢推定として抜けているキーポイントがあるということなのでエラーにしています!

Copy link
Contributor

@qoone qoone Jun 29, 2022

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]にしてる理由ある?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotationId はスネークケースで

Copy link
Contributor

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]にしてる理由ある?

@takahiro-tamenishi

ここ漏れてる?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qoone
すみません。漏れてました。
修正しました。
c966823

# 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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COCO jsonのファイルの中に姿勢推定のデータ化を見分けるフラグがなかったので、アノテーションタイプを入力するようにしています

Copy link
Contributor

@qoone qoone Jun 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カテゴリーの、"keypoints" の値が空かどうかで判断できると思うけど難しい?
現状利用している人に影響が出ちゃうから、インターフェスはどうしても無理な場合以外は、極力変えないようにしたい!

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

了解!

@takahiro-tamenishi takahiro-tamenishi requested a review from qoone June 29, 2022 03:11
@takahiro-tamenishi takahiro-tamenishi self-assigned this Jun 29, 2022
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはなんで、replaceしてるん?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fca4ae8
もし、画像のファイル名などにfalsetrueが入っていたら危険なので修正しました!
evalは調べた感じいらないと判断しましたが、もし必要なようでしたら教えて下さい。

"type": annotation_type,
}
)
if annotation_type in ["bbox", "polygon"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnnotationType を使ってもらえると!

"type": annotation_type,
}
)
elif annotation_type == "pose_estimation":
Copy link
Contributor

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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3つずつ配列にしてるんだと思うけどわかりにくいので、
処理前と処理後の配列とかを例にコメント追加しておいてもらえると!

@takahiro-tamenishi
Copy link
Contributor Author

@qoone
修正しました! readmeも追加しました!

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここって1と2以外じゃない?

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

条件とメッセージの内容がずれてない?

Comment on lines +712 to +715
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)
Copy link
Contributor Author

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以外の場合は、バリデーションエラーにする

@takahiro-tamenishi
Copy link
Contributor Author

@qoone
pip install するのを忘れていて、修正漏れているものがありました。。
修正しました!

@qoone qoone merged commit bd4f4a0 into main Jul 1, 2022
@takahiro-tamenishi takahiro-tamenishi deleted the 842-import-pose-estimation-annotation branch September 22, 2022 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants