Skip to content
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

Feature/120 new specs #121

Merged
merged 25 commits into from
Nov 14, 2022
Merged

Feature/120 new specs #121

merged 25 commits into from
Nov 14, 2022

Conversation

seraphr
Copy link
Contributor

@seraphr seraphr commented Nov 4, 2022

fix #120

  • プロジェクト作成時に、仕様拡張プラグインを利用したプロジェクトが作成されるようにした
  • 既存プロジェクトの編集時、対象プロジェクトが仕様拡張プラグイン無使用の仕様を用いていた場合、その状態を保持するようにした
    • ただ、この機能を試すには、古いcliでプロジェクトを作るか、過去に作ったプロジェクトが要る…

サンプルコマンド

変数を適当に弄って、以下のコマンドを実行
私がテストに利用したデータは以下にアップロードしておいた
https://kurusugawa.jp/nextcloud/f/8863981

ANNO_ID=seraph
ANNO_PASS=****
ANNO_END=https://annofab.com
ANNO_PRJ=3dpc-editor-cli-new-specs3
SCENE_PATH=/vagrant/share/kitti
popy anno3d/app.py project create \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --title ${ANNO_PRJ} \
  --organization_name "Kurusugawa"


popy anno3d/app.py project put_cuboid_label \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ}\
  --label_id "car" \
  --ja_name "車" \
  --en_name "car" \
  --color "(255, 0, 0)"

popy anno3d/app.py project put_cuboid_label \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --label_id "human" \
  --ja_name "人" \
  --en_name "human" \
  --color "(0, 255, 0)"

popy anno3d/app.py project put_segment_label \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --label_id "road" \
  --ja_name "道" \
  --en_name "road" \
  --color "(238, 130, 238)" \
  --segment_type SEMANTIC

popy anno3d/app.py project put_segment_label \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --label_id "wall" \
  --ja_name "壁" \
  --en_name "wall" \
  --color "(0, 182, 110)" \
  --segment_type SEMANTIC

popy anno3d/app.py project put_segment_label \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --label_id "car-seg" \
  --ja_name "車(seg)" \
  --en_name "car-seg" \
  --color "(255, 0, 0)" \
  --segment_type INSTANCE

popy anno3d/app.py project upload_scene \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --frame_per_task 10 \
  --camera_horizontal_fov "calib" \
  --input_data_id_prefix data1 \
  --task_id_prefix data1-task \
  --upload_kind annotation \
  --scene_path ${SCENE_PATH} \
  --force

popy anno3d/app.py project add_preset_cuboid_size \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --key_name smallBox \
  --ja_name 小サイズ \
  --en_name "small size" \
  --width 1 \
  --height 1 \
  --depth 1 \
  --order 1

popy anno3d/app.py project add_preset_cuboid_size \
  --annofab_id ${ANNO_ID} \
  --annofab_pass ${ANNO_PASS} \
  --annofab_endpoint ${ANNO_END} \
  --project_id ${ANNO_PRJ} \
  --key_name bigBox \
  --ja_name 大サイズ \
  --en_name "big size" \
  --width 10 \
  --height 10 \
  --depth 10 \
  --order 2

* anno3d/model/label.pyに定義されていた、MetadataをInfoにして、実際のJson表現とは関係ない型にした
    * 消えた情報は、LabelSpecifier上に実装された。
    * LabelSpecifierは更に抽象化される予定
* label_specifiers.pyに実Json構造に対して中立なインターフェースを追加
* それらを利用して、ProjectModifier / ProjectApi を変更
* 新規にプロジェクトを作る場合、新仕様のプロジェクトが作成されるようにした
* 編集時に編集対象プロジェクトが旧仕様プロジェクトだった場合、その状態を維持するようにした
* put_segment_labelのdefault_ignoreを必須の引数からはずした
@seraphr seraphr changed the title [WIP] Feature/120 new specs Feature/120 new specs Nov 7, 2022
@seraphr seraphr marked this pull request as ready for review November 7, 2022 23:05
Comment on lines 270 to 288
def _project_modifiers(self, project_id: str) -> ProjectModifiers:
current = self._modifiers_dic.get(project_id, None)
if current is not None:
return current

project: Dict[str, Any]
project, _ = self._client.get_project(project_id)
conf: Dict[str, Any] = project["configuration"]
specs_plugin = conf.get("extended_specs_plugin_id", None)

# 仕様拡張プラグインが利用されているかどうかでLabelSpecifiersの実装を入れ替える
if specs_plugin is None:
new = ProjectModifiers(MetadataLabelSpecifiers())
else:
# TODO Pluginに埋まってるバージョンを読んで選択出来るようにしたい
# 現状は、1.0.1しか無い&pluginのdataclassが存在しないのでやってない
new = ProjectModifiers(ExtendedSpecsLabelSpecifiersV1())
self._modifiers_dic[project_id] = new
return new
Copy link
Contributor Author

Choose a reason for hiding this comment

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

基本的に、新旧仕様の動作の切り替えはここで、LabelSpecifiersの実装を入れ替えることで行っている。

ただ、唯一、default_ignoreについてのコードだけ、LabelSpecifiersでは出来ない部分があるので、if書いてある。

Comment on lines 146 to 158
ignore_additional: Optional[IgnoreAdditionalDef]
ignore_id: Optional[str]

# 無視属性の追加は仕様拡張プラグインを使ってる場合は行わない
# ここでifするの微妙だが、ProjectModifiersまで抽象化するのは手間なので、こうしておく
if default_ignore is None or self._label_specifiers.extended_specs_plugin_version() is not None:
ignore_additional = None
ignore_id = None
else:
ignore_additional = default_ignore_additional if default_ignore else default_non_ignore_additional
ignore_id = ignore_additional.id

set_ignore = self._label_specifiers.ignore.set(ignore_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

切り替え用 if その1

Comment on lines 111 to 123
ignore_additional: Optional[IgnoreAdditionalDef]
ignore_id: Optional[str]

# 無視属性の追加は仕様拡張プラグインを使ってる場合は行わない
# ここでifするの微妙だが、ProjectModifiersまで抽象化するのは手間なので、こうしておく
if default_ignore is None or self._label_specifiers.extended_specs_plugin_version() is not None:
ignore_additional = None
ignore_id = None
else:
ignore_additional = default_ignore_additional if default_ignore else default_non_ignore_additional
ignore_id = ignore_additional.id

set_ignore = self._label_specifiers.ignore.set(ignore_id)
Copy link
Contributor Author

@seraphr seraphr Nov 7, 2022

Choose a reason for hiding this comment

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

切り替え用 if その2

その1と全く同じコードだけど、とりあえず2つしかなくて隣り合って定義されているので、そのままにした。
python 関数による抽象化がめんどくさくて…

@yuji38kwmt
Copy link
Collaborator

pyproject.tomlannofabapi>=0.65.0を指定して欲しいです。この指定がないと、古いannofabapiを利用している場合、"import error"が発生すると思います。

anno3d/app.py Show resolved Hide resolved
anno3d/annofab/model.py Outdated Show resolved Hide resolved
builtin_3d_editor_plugin_id = "bdc16348-107e-4fbc-af4a-e482bc84a60f"

# Annofabで定義されている標準三次元エディタ用仕様拡張プラグインのID(dev / production共通)
builtin_3d_extend_specs_plugin_id = "703ababa-96ac-4920-8afb-d4f2bddac7e3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

APIに合わせてextendedの方が良いと思います。

Suggested change
builtin_3d_extend_specs_plugin_id = "703ababa-96ac-4920-8afb-d4f2bddac7e3"
builtin_3d_extended_specs_plugin_id = "703ababa-96ac-4920-8afb-d4f2bddac7e3"

Copy link
Collaborator

Choose a reason for hiding this comment

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

https://github.com/kurusugawa-computer/annofab-api-python-client/blob/199131a8fa24f94b3c27f27685bd0a0a3b1efd0c/annofabapi/plugin.py#L6-L29

annofab-api-python-clientでplugin_idを定義しました。これを参照すればplugin_idの定義する必要はないでしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

annofab-api-python-clientでplugin_idを定義しました。これを参照すればplugin_idの定義する必要はないでしょうか?

それはたしかにそうですね。
とはいえ、この情報をannofab-api-python-clientが持つべきかどうかは、ちょっと怪しい気がしますが。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

変数名変更しました e319150

@seraphr
Copy link
Contributor Author

seraphr commented Nov 8, 2022

pyproject.tomlannofabapi>=0.65.0を指定して欲しいです。この指定がないと、古いannofabapiを利用している場合、"import error"が発生すると思います。

確かに 8a798e6

Copy link
Collaborator

@yuji38kwmt yuji38kwmt left a comment

Choose a reason for hiding this comment

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

新しいanno3dコマンドで作成したプロジェクトと、従来のanno3dコマンドで作成したプロジェクトに対して、以下のコマンドを実行できることを確認しました。

  • project put_cuboid_label
  • project put_segment_label --segment_type INSTANCE
  • project put_segment_label --segment_type SEMANTIC

@yuji38kwmt
Copy link
Collaborator

@seraphr set_rect_annotation_areaコマンドなどを利用すると、アノテーション仕様のメタデータにバージョン情報が格納されます。
バージョン情報がなくても動作するのであれば、バージョン情報は設定しない方が良いと思います。

$ poetry run anno3d project set_rect_annotation_area 7bacc323-c744-4f60-b2b3-c68d87cbe2a5   "(-10.0, 20.0)"   "(-10.0, 20.0)" 
[2022-11-14 06:59:07,130] [17274] [anno3d.app] [INFO] メタデータを更新しました。
[2022-11-14 06:59:07,132] [17274] [anno3d.app] [INFO] {
  "annotationArea": {
    "areaMaxX": "20.0",
    "areaMaxY": "20.0",
    "areaMinX": "-10.0",
    "areaMinY": "-10.0",
    "areaKind": "rect"
  },
  "presetCuboidSizes": {},
  "version": {
    "version": "2"
  }
}

@seraphr
Copy link
Contributor Author

seraphr commented Nov 13, 2022

バージョン情報がなくても動作するのであれば、バージョン情報は設定しない方が良いと思います。

どこから、バージョン情報がなくても動作すると判断したかわからないんですが、バージョン情報が無いと動作しないはずです。
バージョン情報がない場合、ここに書かれている設定が完全に無視されます。

@yuji38kwmt
Copy link
Collaborator

バージョン情報がなくても動作するのであれば、バージョン情報は設定しない方が良いと思います。

どこから、バージョン情報がなくても動作すると判断したかわからないんですが、バージョン情報が無いと動作しないはずです。 バージョン情報がない場合、ここに書かれている設定が完全に無視されます。

なるほど。
バージョン情報がなくても3次元エディタの基本的な機能(cuboidやsegmentを付与できる)を利用できるので、「バージョン情報がなくても動作する」と勘違いしていました。
バージョン情報が何にかかっているのか、理解していませんでした。

@seraphr seraphr merged commit 8fc09af into master Nov 14, 2022
@seraphr seraphr deleted the feature/120_new-specs branch November 14, 2022 07:31
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.

AnnotationV2 および AnnotationSpecsV3 への対応を行う
3 participants