annotation_zip list_attribute_restriction_violation#

アノテーション仕様の属性制約に違反する、アノテーションZIP内のアノテーションを出力します。 「アノテーション × 違反した制約」で1件を出力するため、同じアノテーションが複数行に現れることがあります。 task_id と input_data_id で、違反を含む入力データを特定できます。

Examples#

$ annofabcli annotation_zip list_attribute_restriction_violation --project_id prj1 \
    --task_id file://task.txt --output violations.csv
violations.csv#

project_id

task_id

input_data_id

annotation_id

label_name

attribute_id

attribute_name

attribute_value

restriction_index

restriction_type

restriction_text

restriction

annotation_editor_url

prj1

task1

input1

a1

car

comment

comment

0

Imply

If 'unclear' is checked, 'comment' is not empty.

{"additional_data_definition_id": "comment", "condition": {"_type": "Imply", "premise": {"additional_data_definition_id": "unclear", "condition": {"_type": "Equals", "value": "true"}}, "condition": {"_type": "NotEquals", "value": ""}}}

https://annofab.com/projects/prj1/tasks/task1/editor?#input1/a1

JSON形式でも出力できます。

$ annofabcli annotation_zip list_attribute_restriction_violation --project_id prj1 \
    --task_id task1 --format pretty_json --output violations.json
[
  {
    "project_id": "prj1",
    "task_id": "task1",
    "input_data_id": "input1",
    "annotation_id": "a1",
    "label_name": "car",
    "attribute_id": "comment",
    "attribute_name": "comment",
    "attribute_value": "",
    "restriction_index": 0,
    "restriction_type": "Imply",
    "restriction_text": "If 'unclear' is checked, 'comment' is not empty.",
    "restriction": {
      "additional_data_definition_id": "comment",
      "condition": {
        "_type": "Imply",
        "premise": {
          "additional_data_definition_id": "unclear",
          "condition": {
            "_type": "Equals",
            "value": "true"
          }
        },
        "condition": {
          "_type": "NotEquals",
          "value": ""
        }
      }
    },
    "annotation_editor_url": "https://annofab.com/projects/prj1/tasks/task1/editor?#input1/a1"
  }
]

--task_id を省略すると、ZIP内の全タスクを対象にします。 --project_id を指定すると、アノテーションZIPと現在のアノテーション仕様を取得します。 最新の保存済みアノテーションを検証する場合は、--latest を指定してZIPを更新してください。 省略時は、作成済みのZIPを使用するため、現在のアノテーションとは異なる場合があります。 --temp_dir でZIPのダウンロード先を指定できます。

取得済みのZIPまたは展開ディレクトリを指定する場合は、--project_id の代わりに --annotation を使用し、annotation_specs export の出力を --annotation_specs_json_file で指定してください。 この場合、認証とAPI通信は不要です。

$ annofabcli annotation_specs export --project_id prj1 --output specs.json

$ annofabcli annotation_zip list_attribute_restriction_violation \
    --annotation annotation.zip --annotation_specs_json_file specs.json \
    --task_id task1 --output violations.csv

--annotation_specs_json_file は --project_id と併用することもできます。 この場合、APIから取得する現在の仕様の代わりに、指定した仕様で検証します。

ローカル入力のエディタURLは、Range型は動画、Unknown型は3次元、それ以外は画像のエディタとして生成します。 分類アノテーションなどで種類を指定する必要がある場合は、--annotation_editor_type image|video|3dpc を指定してください。

出力内容#

  • label_name、attribute_name: ラベル名と属性名。

  • attribute_value: 保存されている属性値。未設定の場合はJSONではnull、CSVでは空欄です。

  • restriction_index: 取得した仕様の restrictions 内の0始まりの位置。

  • restriction_type: 制約の種類。属性間制約の場合は Imply です。

  • restriction_text: 制約を読みやすい文字列にしたもの。変換できない場合は元の制約のJSON文字列。

  • restriction: 元の制約。CSVではJSON文字列です。

  • annotation_editor_url: 対象アノテーションを開くURL。

CSVは違反0件でもヘッダを出力します。JSONは空配列を出力します。

名前は英語で出力します。--use_japanese_name を指定すると、ラベル名・属性名・選択肢名と restriction_text 内の名前を日本語で出力します。日本語名がない場合は英語名を使用します。 自由入力の文字列や restriction の内容は変換しません。 --annotation_specs_json_file を指定した場合は、そのファイルに登録された名前を使用します。

$ annofabcli annotation_zip list_attribute_restriction_violation --project_id prj1 \
    --use_japanese_name --output violations.csv

判定仕様#

APIから取得した現在のアノテーション仕様、または指定した仕様JSONを使用します。 アノテーションZIPに対応する仕様を指定してください。 Equals、NotEquals、Matches、NotMatches、Imply、HasLabel を検証します。 Imply は前提が成立した場合のみ後続条件を検証します。 HasLabel のリンク先は、同一タスク・同一入力データ内のアノテーションから解決します。

読取専用属性も検証対象です。結論が CanInput の制約は検証対象外です。 欠落値とnullは空値として扱い、フラグ属性ではfalseとして扱います。デフォルト値は補完しません。 正規表現はPythonの re.fullmatch を使用します。 Annofab提出時の検証を完全に再現するものではありません。

JSONの読み込み失敗、存在しないリンク先、未対応条件などで検証できなかった入力データは、違反なしとは扱いません。 警告を出して残りの処理を続行し、成功した入力データの違反一覧を出力した後、終了コード1で終了します。 ZIPのダウンロード失敗も終了コード1になります。 検証がすべて成功した場合は、違反の有無にかかわらず終了コード0です。

Usage Details#

アノテーションZIPを読み込み、属性制約に違反するアノテーションを出力します。Annofab提出時の検証の完全な再現ではありません。

usage: annofabcli annotation_zip list_attribute_restriction_violation
       [-h] [--yes] [--endpoint_url ENDPOINT_URL]
       [--annofab_user_id ANNOFAB_USER_ID]
       [--annofab_password ANNOFAB_PASSWORD] [--annofab_pat ANNOFAB_PAT]
       [--logdir LOGDIR] [--disable_log] [--debug] (-p PROJECT_ID |
       --annotation ANNOTATION)
       [--annotation_specs_json_file ANNOTATION_SPECS_JSON_FILE]
       [-t TASK_ID [TASK_ID ...]] [--latest] [--temp_dir TEMP_DIR]
       [--annotation_editor_type {image,video,3dpc}]
       [-f {csv,json,pretty_json}] [-o OUTPUT] [--use_japanese_name]

Named Arguments#

-p, --project_id

アノテーションZIPと現在のアノテーション仕様を取得するプロジェクトID。

--annotation

アノテーションZIPまたは展開ディレクトリ。--annotation_specs_json_fileも指定してください。

--annotation_specs_json_file

検証に使用するアノテーション仕様JSON。annotation_specs exportの出力を指定してください。--project_id指定時は、未指定ならAPIから現在の仕様を取得します。

-t, --task_id

対象のタスクのtask_idを指定します。 file:// を先頭に付けると、task_idの一覧が記載されたファイルを指定できます。ファイルを読み込む場合は、ファイル指定を1個だけ渡してください。直接指定するIDや別のファイル指定とは併用できません。

--latest

--project_id指定時、アノテーションZIPを更新してから取得します。更新には数分かかることがあります。

--temp_dir

--project_id指定時、アノテーションZIPのダウンロード先ディレクトリ。

--annotation_editor_type

Possible choices: image, video, 3dpc

URLに使用するエディタの種類。ローカル入力で未指定の場合はアノテーションの種類から推定します。

-f, --format

Possible choices: csv, json, pretty_json

出力フォーマットを指定します。

Default: 'csv'

-o, --output

出力先のファイルパスを指定します。未指定の場合は、標準出力に出力されます。

--use_japanese_name

ラベル名、属性名、選択肢名をアノテーション仕様に登録されている日本語名で出力します。日本語名がない場合は英語名を出力します。

common options (after the subcommand)#

--yes

処理中に現れる問い合わせに対して、常に yes と回答します。

--endpoint_url

Annofab WebAPIのエンドポイントを指定します。

--annofab_user_id

Annofabにログインする際のユーザーID

--annofab_password

Annofabにログインする際のパスワード

--annofab_pat

Annofabにログインする際のパーソナルアクセストークン

--logdir

ログファイルを保存するディレクトリを指定します。

Default: .log

--disable_log

ログを無効にします。

--debug

HTTPリクエストの内容やレスポンスのステータスコードなど、デバッグ用のログが出力されます。

ZIPをダウンロードする場合は、オーナロールまたはアノテーションユーザロールが必要です。ローカルファイルのみの場合は認証不要です。