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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f8a1f3e
bump annofabapi to 0.64.0
seraphr Nov 2, 2022
a3044f7
Annotationのデータ定義と作成をAnnotationV2に対応
seraphr Nov 3, 2022
b4a0b67
コメントを追記
seraphr Nov 4, 2022
6795661
bump annofabapi to 0.65.0
seraphr Nov 4, 2022
92480a9
SpecsV3での旧3dpc-editor仕様対応
seraphr Nov 4, 2022
10aec64
KittiLabelのdecode時に対象のファイルが無い場合、ラベルが無いことにした
seraphr Nov 4, 2022
0100993
仕様拡張プラグインで必要になるdataclassを定義
seraphr Nov 5, 2022
4808cc5
拡張仕様プラグイン対応の準備のため、label_specifiersへの定義を追加
seraphr Nov 5, 2022
9286a23
拡張仕様プラグイン対応の準備のため、LabelSpecification / ProjectModifierをインスタンス化して利用するよ…
seraphr Nov 6, 2022
fafc9c7
metadataにignore / layerが存在しない時にエラーになるのを修正
seraphr Nov 6, 2022
85bcfc7
意図したJsonへのエンコードが行われず、アノテーションの登録が出来なくなっていたのを修正
seraphr Nov 6, 2022
6942e82
debugプリントが残っていたのを削除
seraphr Nov 7, 2022
1362b44
LabelSpecifiersを、抽象基底クラスとそれを継承するMetadataLabelSpecifiersに分離した
seraphr Nov 7, 2022
5de0ebf
未使用のDataSpecifier _segment_kindを削除
seraphr Nov 7, 2022
508b28d
ExtendSpecsLabelSpecifiersを追加
seraphr Nov 7, 2022
55872d8
仕様拡張プラグインによる三次元エディタプロジェクトを作成・編集出来るようにした
seraphr Nov 7, 2022
fc82dda
新仕様のプロジェクトで無視属性が作成されてしまうのを修正
seraphr Nov 7, 2022
91f336c
ラベルの情報として、annotation_typeとfield_valuesを出力するようにした
seraphr Nov 7, 2022
939ac4b
コマンドサンプルを更新
seraphr Nov 7, 2022
faa649a
コメントを追記
seraphr Nov 7, 2022
8a798e6
annofabapi = ">=0.65.0"
seraphr Nov 8, 2022
934c733
拡張仕様プラグインを利用している時に、default_ignoreが指定された場合、警告を出すようにした
seraphr Nov 8, 2022
b716f02
fix typo
seraphr Nov 8, 2022
e319150
rename builtin_3d_extend_specs_plugin_id to builtin_3d_extended_specs…
seraphr Nov 8, 2022
75b465b
rename 仕様拡張プラグイン to 拡張仕様プラグイン
seraphr Nov 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions anno3d/annofab/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ class IgnoreAdditionalDef:

default_ignore_additional = IgnoreAdditionalDef("__3dpc-editor-default-ignore", "無視", "ignore", True)
default_non_ignore_additional = IgnoreAdditionalDef("__3dpc-editor-non-default-ignore", "無視", "ignore", False)

# Annofabで定義されている標準三次元エディタプラグインのID(dev / production共通)
builtin_3d_editor_plugin_id = "bdc16348-107e-4fbc-af4a-e482bc84a60f"

# Annofabで定義されている標準三次元エディタ用拡張仕様プラグインのID(dev / production共通)
builtin_3d_extended_specs_plugin_id = "703ababa-96ac-4920-8afb-d4f2bddac7e3"
131 changes: 118 additions & 13 deletions anno3d/annofab/model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import typing
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Tuple, Union

from annofabapi.dataclass.annotation_specs import (
AdditionalDataDefinitionV2,
AdditionalDataRestriction,
AnnotationSpecsV2,
AnnotationSpecsV3,
InspectionPhrase,
LabelV2,
LabelV3,
)
from annofabapi.dataclass.job import ProjectJobInfo
from annofabapi.dataclass.project import Project
Expand All @@ -18,12 +19,14 @@
@dataclass
class Label(DataClassJsonMixin):
label_id: str
annotation_type: str
ja_name: str
en_name: str
color: Tuple[int, int, int] = field(
# `Label.schema()`を実行するとエラーが発生するため、mm_fieldをした。https://github.com/lidatong/dataclasses-json/issues/318
metadata=config(mm_field=fields.Tuple((fields.Integer(), fields.Integer(), fields.Integer())))
)
field_values: Dict[str, typing.Any]
metadata: Dict[str, str]


Expand Down Expand Up @@ -73,47 +76,149 @@ class CuboidAnnotationDetailData(DataClassJsonMixin):
version: str = "2"


class UnknownDataField(fields.Field):
"""
FullAnnotationDataUnknownのdataのserialize / deserialize定義
FullAnnotationDataUnknownのdataは文字列型で、3d-editorのCuboidの場合、json形式文字列を埋めないといけないが、str型だと不便。
なので、dump / load時に文字列との相互変換をするような定義をしておく
"""

_type: typing.Any

def __init__(self, cls: typing.Type, **additional_metadata) -> None:
"""

Args:
cls: 実際の型
**additional_metadata:
"""

super().__init__(**additional_metadata)
self._type = cls

def encode(self, value: typing.Any) -> str:
return typing.cast(str, value.to_json(ensure_ascii=False))

def _serialize(self, value: typing.Any, attr: Union[str, None], obj: typing.Any, **kwargs) -> str:
return self.encode(value)

def decode(self, value: str) -> typing.Any:
return self._type.from_json(value)

def _deserialize(
self, value: str, attr: Union[str, None], data: Union[typing.Mapping[str, typing.Any], None], **kwargs
) -> typing.Any:
return self.decode(value)


cuboid_data_field = UnknownDataField(CuboidAnnotationDetailData)


@dataclass
class CuboidFullAnnotationData(DataClassJsonMixin):
data: CuboidAnnotationDetailData = field(
metadata=config(mm_field=cuboid_data_field, encoder=cuboid_data_field.encode, decoder=cuboid_data_field.decode)
)
_type: str = "Unknown"


@dataclass
class CuboidAnnotationDetailBody(DataClassJsonMixin):
"""Cuboid用 AnnotationDetailContentInputInner"""

data: CuboidFullAnnotationData
_type: str = "Inner"

@classmethod
def from_detail_data(cls, data: CuboidAnnotationDetailData) -> "CuboidAnnotationDetailBody":
return CuboidAnnotationDetailBody(data=CuboidFullAnnotationData(data=data))

@classmethod
def from_shape(cls, shape: CuboidShape) -> "CuboidAnnotationDetailBody":
return cls.from_detail_data(CuboidAnnotationDetailData(shape))


@dataclass
class AnnotationPropsForEditor:
can_delete: bool


@dataclass
class CuboidAnnotationDetail(DataClassJsonMixin):
class CuboidAnnotationDetailCreate(DataClassJsonMixin):
"""Cuboid用AnnotationDetailV2Createに対応する型"""

annotation_id: str
account_id: str
label_id: str
is_protected: bool
data: CuboidAnnotationDetailData
data_holding_type: str = "inner"
body: CuboidAnnotationDetailBody
editor_props: AnnotationPropsForEditor
additional_data_list: list = field(default_factory=list) # 型を定義してないので空を前提としておく
_type: str = "Create"


@dataclass
class CuboidAnnotations(DataClassJsonMixin):
"""CLIからCuboidAnnotationを生成する場合に利用する AnnotationV2Input"""

project_id: str
task_id: str
input_data_id: str
details: List[CuboidAnnotationDetail]
details: List[CuboidAnnotationDetailCreate]
format_version: str = "2.0.0"


@dataclass
class OneIntegerFieldValue(DataClassJsonMixin):
"""
LabelV3.field_valuesに格納される値の種別の一つ
整数値を一つだけ保持するValue
"""

value: int
_type: str = "OneIntegerFieldValue"


@dataclass
class CuboidFieldValues(DataClassJsonMixin):
"""Cuboid用LabelV3のfield_values値 常に空"""


@dataclass
class SegmentFieldValues(DataClassJsonMixin):
"""Segment用LabelV3のfield_values値"""

layer: OneIntegerFieldValue
"""セグメントがどのレイヤーに所属するかを表す値。 0以上の整数値"""

@staticmethod
def from_values(layer: int) -> "SegmentFieldValues":
return SegmentFieldValues(OneIntegerFieldValue(layer))


@dataclass
class AnnotationSpecsRequestV2(DataClassJsonMixin):
labels: List[LabelV2]
class AnnotationSpecsRequestV3(DataClassJsonMixin):
labels: List[LabelV3]
additionals: List[AdditionalDataDefinitionV2]
restrictions: List[AdditionalDataRestriction]
inspection_phrases: List[InspectionPhrase]
comment: str
auto_marking: bool
annotation_type_version: Optional[str]
format_version: str
last_updated_datetime: Optional[str]
option: Union[AnnotationSpecsMovieOption, None]
metadata: Optional[Dict[str, str]]

@staticmethod
def from_specs(specs: AnnotationSpecsV2) -> "AnnotationSpecsRequestV2":
return AnnotationSpecsRequestV2(
def from_specs(specs: AnnotationSpecsV3) -> "AnnotationSpecsRequestV3":
return AnnotationSpecsRequestV3(
labels=specs.labels if specs.labels is not None else [],
additionals=specs.additionals if specs.additionals is not None else [],
restrictions=specs.restrictions if specs.restrictions is not None else [],
inspection_phrases=specs.inspection_phrases if specs.inspection_phrases is not None else [],
comment="",
auto_marking=False,
format_version=specs.format_version if specs.format_version is not None else "2.1.0",
annotation_type_version=specs.annotation_type_version,
format_version=specs.format_version if specs.format_version is not None else "3.0.0",
last_updated_datetime=specs.updated_datetime,
option=specs.option,
metadata=specs.metadata,
Expand Down
Loading