シーンとインプットの操作
18 分
さまざまなシーンモダリティの詳細については、==!シーンタイプ!==セクションを参照してください。 kognicユーザーとして、 kognicioclient コンストラクタに client organization id を指定することで、クライアント組織に代わってシーンを作成できます。 シーンの作成 各シーンリソースには、対応するタイプのシーンを作成するための create メソッドがあります。対応するシーンモデルを入力として受け取ります。例えば、 cameras シーンを作成するには以下のようにします。 from kognic io model scene cameras import cameras scene = cameras( ) created scene = client cameras create(cameras scene) scene uuid = created scene uuid ご覧のとおり、 create メソッドは関連する scene uuid を返します。この scene uuid は後でシーンの操作に使用できます。この時点ですべてのファイルがkognic platformにアップロードされ、シーンの前処理が開始されます。前処理が完了すると、シーンが作成されたとみなされます。さまざまなシーンステータスの詳細については、 docid\ mf7 5gllqrkg to ev3yd セクションを参照してください。 実験中は dryrun パラメータを使用すると便利です。これにより、シーンのフォーマットを検証しますが、シーンは作成されません。 シーンステータス シーンがアップロードされると、プラットフォームで利用可能になる前に前処理が行われる場合があります。このプロセス中、シーンの status プロパティを使用して進捗状況を追跡できます。 status 説明 indexed シーンはクラウドリソースで作成・検証済みですが、クラウドからデータは送出されていません。uiまたはapiで利用可能にするまでこの状態が維持されます。 pending シーンは検証済みですが、サーバーは関連リソースのアップロードを待機しています。 processing 関連データがアップロードされ、kognic platformによって処理中です。ファイルフォーマットの変換が行われる場合があります。 created シーンが作成され、プラットフォームで利用可能です。 failed シーンの変換に失敗しました。詳細は関連するエラーメッセージを参照してください。 invalidated シーンがロードされなかったため無効化されました。 invalidated 複数回アップロードされたため無効化されました。 invalidated scene was invalidated because it was incorrectly created シーンからインプットを作成する シーンが作成されると、プロジェクトとインプットバッチに関連付けることでインプットを作成できます。以下のプロジェクト設定を例に考えます。 organization # root for projects and scenes └── projects ├── project a ├── batch 1 completed ├── batch 2 open ├── request 1 ├── input 9c08f7a3 3216 4bd6 a41a 1dda6f66f53e – using scene 0edb ├── input ddf548e3 9806 433c afb5 fb951a721462 using scene 37d9 └── └── request 2 └── batch 3 pending └── project b ├── batch 1 └── └── scenes ├── scene 0edb8f59 a8ea 4c9b aebb a3caaa6f2ba3 ├── scene 37d9dda4 3a29 4fcb 8a71 6bf16d5a9c36 └── create from scene メソッドはシーンからインプットを作成するために使用します。このメソッドはシーンのuuidと、プロジェクト、バッチ、アノテーションタイプなどのアノテーション情報を入力として受け取ります。例えば、 project a と batch 2 にインプットを作成するには以下のようにします。 client cameras create from scene( scene uuid="0edb8f59 a8ea 4c9b aebb a3caaa6f2ba3", project="project a", # important this is the external id and not the title batch="batch 2" # important this is the external id and not the title ) 上記のコードは、プロジェクト project a のバッチ batch 2 内のすべてのリクエストに対して、シーンのインプットを作成します。 batch パラメータが省略された場合、そのプロジェクトの最新のオープンバッチが使用されます。同じシーンを後で他のプロジェクトやバッチのインプット作成に再利用することもできます。 インプットを直接作成する 上記の2ステップのプロセスの代わりに、インプットを直接作成すると便利な場合がよくあります。これを行うには、対応するシーンタイプの create メソッドにアノテーション情報を直接渡すだけです。例えば、 project a と batch 2 にインプットを作成するには以下のようにします。 client cameras sequence create( , project="project a", # important this is the external id and not the title batch="batch 2" # important this is the external id and not the title ) this would trigger the scene creation process, and once the scene is created, inputs are created in all requests in the given batch if the batch parameter is omitted, the latest open batch for the project will be used we also provide a wrapper function create inputs to help with this process, see これによりシーン作成プロセスがトリガーされ、シーンが作成されると、指定されたバッチ内のすべてのリクエストにインプットが作成されます。 batch パラメータが省略された場合、そのプロジェクトの最新のオープンバッチが使用されます。このプロセスを補助するラッパー関数 create inputs も提供しています。詳細は docid\ mf7 5gllqrkg to ev3yd を参照してください。 シーンの一覧を取得する この機能はバージョン1 6 0で追加されました。 kognic platformにアップロードされたシーンの一覧を取得することが役立つ場合があります。例えば、シーン作成中にステータスを確認する際などに使用します。シーンは以下の方法で取得できます。 scene uuids = \["cca60a67 cb68 4645 8bae 00c6e6415555", "cc8776d0 f537 4094 8b11 8c2111741e2f"] client scene get scenes by uuids(scene uuids=scene uuids) レスポンス レスポンスは以下のプロパティを含む scene オブジェクトのリストです。 プロパティ 説明 uuid kognic platform内でシーンを識別するために使用されるuuid external id シーン作成時に指定された外部id scene type シーンのタイプ( docid\ i8t2meikkpcu2gloni5yo を参照 ) status シーンのステータス ( docid\ mf7 5gllqrkg to ev3yd を参照 ) created シーンが作成された日時 calibration id シーンに使用されたキャリブレーション(存在する場合) view link kognic platformでシーンをするためのurl error message シーン作成中にエラーが発生した場合はエラーメッセージが含まれ、それ以外の場合は none インプットの一覧を取得する この機能はバージョン1 7 0で追加されました。 インプットは query inputs メソッドを使用してプラットフォームから取得できます。使用方法は以下のとおりです。 scene uuids = \["cca60a67 cb68 4645 8bae 00c6e6415555", "cc8776d0 f537 4094 8b11 8c2111741e2f"] client scene get scenes by uuids(scene uuids=scene uuids) additional filter parameters for querying inputs are listed below parameter description project project identifier to filter by batch which batch in the project to return inputs for scene uuids return inputs using scenes matching the supplied uuids external ids return inputs using scenes matching the supplied external ids response the response is a list of input objects containing the following properties property description uuid id used to identify the input within the kognic platform scene uuid id used to identify the scene that the input is using request uid id used to identify the request that the input belongs to view link a url to view the input in the kognic platform invalidate scenes note this feature is new in version 1 6 0 if issues are detected upstream related to scenes created, it is possible to invalidate them this could be useful during development or if issues are detected with the data invalidating a scene means that it will be removed from requests, meaning that all inputs using the scene will be deleted in turn invalidated scenes will not produce annotations and any completed annotations of the scene will be removed there is no way to undo this operation so use with caution from kognic io model scene invalidated reason import sceneinvalidatedreason scene uuids = \["0edb8f59 a8ea 4c9b aebb a3caaa6f2ba3", "37d9dda4 3a29 4fcb 8a71 6bf16d5a9c36"] reason = sceneinvalidatedreason bad content client scene invalidate scenes(scene uuids, reason) インプットの取得に使用できる追加のフィルターパラメータを以下に示します。 理由 説明 bad content シーンがロードされないか、無効なキャリブレーションなどの誤ったメタデータが含まれている duplicate 同じシーンが複数回作成された場合 incorrectly created シーンが意図せず作成された場合 インプットを削除する この機能はバージョン1 6 0で追加されました。 作成されたインプットに関連する問題が上流で検出された場合、インプットを削除することができます。これは、問題がシーン自体ではなくインプットに関連している場合に役立ちます。例えば、ライダーとカメラのシーンに2つのインプットがある場合、一方は2d/3dでアノテーションを行い、もう一方は2dのみでアノテーションを行うとします。問題がキャリブレーションの誤りである場合、2dインプットはそのまま使用できますが、2d/3dインプットは削除する必要があります。 インプットを削除すると、そのインプットに対するアノテーションは生成されなくなり、完了済みのアノテーションも削除されます。この操作は元に戻すことができないため、慎重に使用してください。 input uuid = "9c08f7a3 3216 4bd6 a41a 1dda6f66f53e" client input delete input(input uuid) 1回の呼び出しで複数のインプットを作成する この機能はバージョン1 1 9で追加されました。 インプットの作成プロセスは非同期であるため、処理を続行する前にインプットの作成を待機することが役立つ場合があります。これを実現するために、複数のシーンとインプットを作成し、作成(または失敗)されるまで待機して結果を返すラッパー関数 create inputs を提供しています。この関数は、すべてのインプットがいずれかの方法で完了するか、返す結果が生じるまでブロックします。この関数は scenewithpreannotation (シーンとオプションのプレアノテーションを含む新しいラッパーオブジェクト)のリストと、通常のインプット作成パラメータを受け取ります。 from kognic io tools input creation import create inputs, scenewithpreannotation, inputcreationstatus from kognic io model scene import lidarsandcamerassequence from kognic openlabel models import openlabelannotation scenes with pre annotations list\[scenewithpreannotation] = \[ scenewithpreannotation( scene=lidarsandcamerassequence( ), preannotation=openlabelannotation( ) # optional ), ] for input result in create inputs(client, scenes with pre annotations, "project identifier", batch="batch identifier") \# do something with the result if input result status == inputcreationstatus created print(f"input {input result external id} was created, got uuid {input result input uuid}") elif input result status == inputcreationstatus failed print(f"input {input result external id} failed to be created at stage {input result error stage} with error {input result error message}") else print(f"input {input result external id} is in status {input result status}") この関数は wait timeout と sleep time パラメータも受け付けることに注意してください。これらは待機動作を制御するために使用できます。 wait timeout パラメータはインプットの作成/失敗を待機する最大時間を指定し、 sleep time は各チェック間のスリープ時間を指定します。単位は秒です。インプットの作成にかかる時間はサイズと作成するインプットの数によって異なるため、 wait timeout は適切に設定する必要があります。デフォルト値は30分で、すべてのシーンジョブがコミットされた時点から計測されます。 シーン作成の完了を待機する 処理を続行する前にシーンの作成完了を待機することが役立つ場合があります。これはutils pyの以下の例を使用して実現できます。 import time from kognic io client import kognicioclient from kognic io model import scenestatus def wait for scene job(client kognicioclient, scene uuid str, timeout=20) > scenestatus start time = time time() while (time time() start time) < timeout response = client scene get scenes by uuids(scene uuids=\[scene uuid]) scene = response\[0] if scene status in \[scenestatus created, scenestatus failed] return scene status time sleep(1) raise exception(f"job was not finished {scene uuid}")
