x4d-devkit 0.56.0rc1__tar.gz → 0.57.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {x4d_devkit-0.56.0rc1/x4d_devkit.egg-info → x4d_devkit-0.57.0}/PKG-INFO +1 -1
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/pyproject.toml +1 -1
- x4d_devkit-0.57.0/tests/test_image_polygon.py +401 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_preannotation.py +5 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_sdk_api.py +1 -1
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_clip.py +78 -14
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_geometry.py +161 -35
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_preannotation.py +1 -1
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_schema.py +57 -11
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_schema_migration.py +8 -4
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0/x4d_devkit.egg-info}/PKG-INFO +1 -1
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit.egg-info/SOURCES.txt +1 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/LICENSE +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/README.md +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/setup.cfg +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_accounts.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_annotation_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_annotation_document_hash.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_annotation_reference.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_assets_client.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_boundary.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_box.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_build_info.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_category_audit.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_clean_basemap.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_clean_basemap_client.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_cli_auth.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_client_json_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_client_projects.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_clip_archives.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_contract_validation.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_coordinate_frames.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_current_state.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_current_state_identity_consumers_example.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_dataset_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_dataset_identity.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_detection_eval.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_evaluate.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_export_bundle.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_clip.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_conditional_rules.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_enum_set.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_export.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_external_predictions.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_geometry.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_groups.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_reference.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_review.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_schema_migration.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_schema_registry_client.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_schema_upgrade.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_source.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_image_work_session.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_inference_input.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_inference_schemas.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_inference_service.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_label_schemas.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_lidar_materialization.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_loader.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_matching.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_metrics.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_models.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_parse_equivalence.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_platform_pose.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_preannotation_client.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_project_discovery.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_reconstruction_client.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_release_gate.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_roadmark_preview.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_semantic_scene_authoring.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_semantic_scene_client.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_semantic_scene_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_semantic_scene_independent.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_semantic_scene_native_clip.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_source_attributes.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_source_content.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_time_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_token.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_tracking_eval.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_training_identity.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_transform.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_transform_chain.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_validation.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_vector_map.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_vector_map_geometry.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_vector_map_session.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_work_session.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/tests/test_work_session_validation_reuse.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/__init__.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/_image_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/accounts.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/annotation_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/annotation_reference.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/audit.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/build_info.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/clean_basemap.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/cli.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/__init__.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/_origin.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/accounts.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/annotation_reference.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/assets.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/bags.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/capabilities.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/checkpoints.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/clean_basemap.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/client.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/clip_work_sessions.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/clips.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/dataset_identity.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/image_clips.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/image_exports.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/image_preannotations.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/image_review.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/image_schemas.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/image_work_sessions.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/label_schemas.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/preannotation.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/projects.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/reconstruction.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/semantic_scene.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/semantic_scene_authoring.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/services.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/client/test_sets.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/consumer_identity.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/coordinate_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/core/__init__.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/core/loader.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/core/models.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/core/token.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/core/transform.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/current_state.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/dataset_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/dataset_identity.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/eval/__init__.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/eval/api.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/eval/box.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/eval/detection.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/eval/matching.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/eval/metrics.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/eval/tracking.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/export_bundle.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_export.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_groups.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_reference.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_review.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_schema_upgrade.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_source.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/image_work_session.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/inference/__init__.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/inference/input.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/inference/models.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/inference/schemas.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/inference/service.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/inference/tasks.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/json_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/label_schema.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/lidar_materialization.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/materialize.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/project_discovery.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/roadmark_preview.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/semantic_scene_authoring.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/semantic_scene_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/source_content.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/time_contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/training_identity.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/validation/__init__.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/validation/contract.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/validation/platform_pose.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/validation/report.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/validation/validator.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/vector_map.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/vector_map_geometry.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit/work_session.py +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit.egg-info/dependency_links.txt +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit.egg-info/entry_points.txt +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit.egg-info/requires.txt +0 -0
- {x4d_devkit-0.56.0rc1 → x4d_devkit-0.57.0}/x4d_devkit.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "x4d-devkit"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.57.0"
|
|
8
8
|
description = "Official X-4D external SDK and CLI for datasets, platform APIs, training bridges, and automation"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"""Polygon geometry, multi-geometry categories and conditional image text (#246)."""
|
|
2
|
+
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from x4d_devkit import ImageGeometryError, parse_image_geometry
|
|
8
|
+
from x4d_devkit._image_contract import ImageContractError, fingerprint
|
|
9
|
+
from x4d_devkit.image_clip import build_image_identity, parse_image_clip
|
|
10
|
+
from x4d_devkit.image_geometry import POLYGON_MIN_AREA, parse_image_attribute_ranges
|
|
11
|
+
from x4d_devkit.image_schema import (
|
|
12
|
+
build_image_schema_snapshot,
|
|
13
|
+
image_category_geometry_types,
|
|
14
|
+
parse_image_schema_body,
|
|
15
|
+
parse_image_schema_record,
|
|
16
|
+
)
|
|
17
|
+
from x4d_devkit.image_schema_migration import (
|
|
18
|
+
MAPPING_CONTRACT,
|
|
19
|
+
ImageSchemaMigrationConflict,
|
|
20
|
+
build_image_schema_migration_preview,
|
|
21
|
+
image_schema_migration_candidate,
|
|
22
|
+
)
|
|
23
|
+
from tests.image_fixtures import clip_payload, schema_body
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# --- geometry -------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def polygon(*points, ids=None):
|
|
30
|
+
ids = ids or [f"v{index}" for index in range(len(points))]
|
|
31
|
+
return {
|
|
32
|
+
"geometry_type": "polygon_2d",
|
|
33
|
+
"vertices": [
|
|
34
|
+
{"vertex_id": vertex_id, "x": x, "y": y}
|
|
35
|
+
for vertex_id, (x, y) in zip(ids, points)
|
|
36
|
+
],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse(value, width=100, height=80):
|
|
41
|
+
return parse_image_geometry(value, width=width, height=height)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
SQUARE = ((10, 10), (60, 10), (60, 50), (10, 50))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.parametrize(
|
|
48
|
+
"points",
|
|
49
|
+
[
|
|
50
|
+
SQUARE, # clockwise in image coordinates (y down)
|
|
51
|
+
tuple(reversed(SQUARE)), # counter-clockwise
|
|
52
|
+
((0, 0), (100, 0), (0, 80)), # touches the closed image bounds
|
|
53
|
+
((10, 10), (35, 10), (60, 10), (60, 50), (10, 50)), # adjacent collinear
|
|
54
|
+
((10.5, 10.25), (60, 10), (35.125, 49.75)),
|
|
55
|
+
((10, 10), (60, 10), (60, 50), (35, 20), (10, 50)), # concave
|
|
56
|
+
],
|
|
57
|
+
)
|
|
58
|
+
def test_simple_polygons_round_trip_exactly_in_either_orientation(points):
|
|
59
|
+
raw = polygon(*points, ids=[f"id_{len(points) - i}" for i in range(len(points))])
|
|
60
|
+
parsed = parse(raw)
|
|
61
|
+
assert parsed.geometry_type == "polygon_2d"
|
|
62
|
+
assert parsed.to_dict() == raw
|
|
63
|
+
assert parsed.vertex_ids == tuple(row["vertex_id"] for row in raw["vertices"])
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@pytest.mark.parametrize(
|
|
67
|
+
"value, code",
|
|
68
|
+
[
|
|
69
|
+
(polygon((10, 10), (60, 10)), "invalid_image_polygon"),
|
|
70
|
+
(polygon(*SQUARE, (10, 10)), "repeated_image_polygon_closure"),
|
|
71
|
+
(polygon((10, 10), (60, 10), (60, 10), (10, 50)), "zero_length_image_edge"),
|
|
72
|
+
(polygon((10, 10), (30, 10), (60, 10)), "degenerate_image_polygon"),
|
|
73
|
+
(polygon((10, 10), (30, 10), (60, 10), (40, 10)), "degenerate_image_polygon"),
|
|
74
|
+
# bow-tie
|
|
75
|
+
(polygon((10, 10), (60, 50), (60, 10), (10, 50)), "self_intersecting_image_polygon"),
|
|
76
|
+
# a vertex touching a non-adjacent edge
|
|
77
|
+
(
|
|
78
|
+
polygon((10, 10), (60, 10), (60, 50), (35, 10), (10, 50)),
|
|
79
|
+
"self_intersecting_image_polygon",
|
|
80
|
+
),
|
|
81
|
+
# non-consecutive repeated point (figure eight pinch)
|
|
82
|
+
(
|
|
83
|
+
polygon((10, 10), (30, 30), (50, 10), (50, 50), (30, 30), (10, 50)),
|
|
84
|
+
"self_intersecting_image_polygon",
|
|
85
|
+
),
|
|
86
|
+
# adjacent edges backtrack along the same line
|
|
87
|
+
(
|
|
88
|
+
polygon((10, 10), (60, 10), (40, 10), (40, 50)),
|
|
89
|
+
"self_intersecting_image_polygon",
|
|
90
|
+
),
|
|
91
|
+
(polygon((10, 10), (101, 10), (60, 50)), "image_coordinate_out_of_bounds"),
|
|
92
|
+
(polygon((10, 10), (60, -1), (60, 50)), "image_coordinate_out_of_bounds"),
|
|
93
|
+
(polygon((10, 10), (60, 10), (60, True)), "invalid_image_coordinate"),
|
|
94
|
+
(polygon((10, 10), (60, 10), (60, 50), ids=["a", "b", "a"]), "duplicate_image_vertex"),
|
|
95
|
+
(polygon((10, 10), (60, 10), (60, 50), ids=["a", "b", " c"]), "invalid_image_identifier"),
|
|
96
|
+
(
|
|
97
|
+
polygon((0, 0), (1e-4, 0), (0, 1e-4)), # 5e-9 px^2 sliver
|
|
98
|
+
"degenerate_image_polygon",
|
|
99
|
+
),
|
|
100
|
+
],
|
|
101
|
+
)
|
|
102
|
+
def test_invalid_polygons_fail_with_structured_codes(value, code):
|
|
103
|
+
with pytest.raises(ImageGeometryError) as error:
|
|
104
|
+
parse(value)
|
|
105
|
+
assert error.value.code == code
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@pytest.mark.parametrize("value", [float("nan"), float("inf")])
|
|
109
|
+
def test_non_finite_polygon_coordinates_are_rejected(value):
|
|
110
|
+
with pytest.raises(ImageGeometryError) as error:
|
|
111
|
+
parse(polygon((10, 10), (60, 10), (value, 50)))
|
|
112
|
+
assert error.value.code in {"invalid_image_json", "invalid_image_coordinate"}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_polygon_fields_are_closed_and_have_no_segment_ranges():
|
|
116
|
+
raw = polygon(*SQUARE)
|
|
117
|
+
with pytest.raises(ImageGeometryError) as error:
|
|
118
|
+
parse({**raw, "closed": True})
|
|
119
|
+
assert error.value.code == "invalid_image_fields"
|
|
120
|
+
with pytest.raises(ImageGeometryError) as error:
|
|
121
|
+
parse_image_attribute_ranges([], geometry=parse(raw))
|
|
122
|
+
assert error.value.code == "invalid_image_range_geometry"
|
|
123
|
+
assert POLYGON_MIN_AREA == 1e-6
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_large_polygon_validation_uses_a_sweep():
|
|
127
|
+
import math
|
|
128
|
+
|
|
129
|
+
count = 2000
|
|
130
|
+
points = tuple(
|
|
131
|
+
(
|
|
132
|
+
500 + 400 * math.cos(2 * math.pi * i / count),
|
|
133
|
+
500 + 400 * math.sin(2 * math.pi * i / count),
|
|
134
|
+
)
|
|
135
|
+
for i in range(count)
|
|
136
|
+
)
|
|
137
|
+
assert len(parse(polygon(*points), width=1000, height=1000).vertex_ids) == count
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# --- Schema ---------------------------------------------------------------
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def polygon_body():
|
|
144
|
+
body = schema_body()
|
|
145
|
+
body["categories"][1]["geometry_types"] = ["box_2d", "polygon_2d"]
|
|
146
|
+
del body["categories"][1]["geometry_type"]
|
|
147
|
+
body["categories"].append(
|
|
148
|
+
{
|
|
149
|
+
"id": "ignore",
|
|
150
|
+
"display_name": "Ignore region",
|
|
151
|
+
"geometry_type": "polygon_2d",
|
|
152
|
+
"color": "#445566",
|
|
153
|
+
"attributes": [],
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
body["task_views"][0]["category_ids"].append("ignore")
|
|
157
|
+
body["task_views"][1]["category_ids"] = ["line", "box"]
|
|
158
|
+
body["task_views"][1]["description_fields"] = [
|
|
159
|
+
{"id": "phrase", "display_name": "Phrase", "required": True, "target": "object"},
|
|
160
|
+
{
|
|
161
|
+
"id": "caption",
|
|
162
|
+
"display_name": "Caption",
|
|
163
|
+
"required": True,
|
|
164
|
+
"target": "image",
|
|
165
|
+
"applies_when": "applicable_objects",
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
return body
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_existing_single_geometry_schema_fingerprint_is_unchanged():
|
|
172
|
+
# Bodies written before #246 keep their exact fingerprint and validity.
|
|
173
|
+
assert parse_image_schema_body(schema_body()).identity.fingerprint == (
|
|
174
|
+
"sha256:09feb13e42be49c84ea3f163ecee4d57236dabb4e98bdf157936e2f6457a3d91"
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_multi_geometry_categories_parse_and_report_their_allowed_types():
|
|
179
|
+
body = parse_image_schema_body(polygon_body()).to_dict()
|
|
180
|
+
categories = {row["id"]: row for row in body["categories"]}
|
|
181
|
+
assert image_category_geometry_types(categories["box"]) == ("box_2d", "polygon_2d")
|
|
182
|
+
assert image_category_geometry_types(categories["ignore"]) == ("polygon_2d",)
|
|
183
|
+
assert image_category_geometry_types(categories["line"]) == ("polyline_2d",)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _category_change(change):
|
|
187
|
+
body = polygon_body()
|
|
188
|
+
change(body["categories"][1])
|
|
189
|
+
return body
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@pytest.mark.parametrize(
|
|
193
|
+
"change",
|
|
194
|
+
[
|
|
195
|
+
lambda c: c.update(geometry_types=["polygon_2d"]),
|
|
196
|
+
lambda c: c.update(geometry_types=["box_2d", "box_2d"]),
|
|
197
|
+
lambda c: c.update(geometry_types=["box_2d", "mask_2d"]),
|
|
198
|
+
lambda c: c.update(geometry_types="box_2d"),
|
|
199
|
+
lambda c: c.update(geometry_types=[]),
|
|
200
|
+
lambda c: c.update(geometry_type="box_2d"),
|
|
201
|
+
lambda c: c.pop("geometry_types"),
|
|
202
|
+
lambda c: c.update(
|
|
203
|
+
attributes=[
|
|
204
|
+
{
|
|
205
|
+
"id": "seg",
|
|
206
|
+
"display_name": "Seg",
|
|
207
|
+
"type": "boolean",
|
|
208
|
+
"required": False,
|
|
209
|
+
"scopes": ["segment"],
|
|
210
|
+
"values": [],
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
),
|
|
214
|
+
],
|
|
215
|
+
)
|
|
216
|
+
def test_invalid_category_geometry_declarations_are_rejected(change):
|
|
217
|
+
with pytest.raises(ImageContractError):
|
|
218
|
+
parse_image_schema_body(_category_change(change))
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def test_segment_scope_requires_a_single_polyline_category():
|
|
222
|
+
body = schema_body()
|
|
223
|
+
body["categories"][0]["geometry_types"] = ["polyline_2d", "polygon_2d"]
|
|
224
|
+
del body["categories"][0]["geometry_type"]
|
|
225
|
+
with pytest.raises(ImageContractError, match="single-geometry polyline"):
|
|
226
|
+
parse_image_schema_body(body)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@pytest.mark.parametrize(
|
|
230
|
+
"field",
|
|
231
|
+
[
|
|
232
|
+
{"id": "f", "display_name": "F", "required": True, "target": "object", "applies_when": "applicable_objects"},
|
|
233
|
+
{"id": "f", "display_name": "F", "required": True, "applies_when": "applicable_objects"},
|
|
234
|
+
{"id": "f", "display_name": "F", "required": True, "target": "image", "applies_when": "always"},
|
|
235
|
+
{"id": "f", "display_name": "F", "required": True, "target": "image", "applies_when": None},
|
|
236
|
+
],
|
|
237
|
+
)
|
|
238
|
+
def test_applies_when_is_only_a_known_image_target_condition(field):
|
|
239
|
+
body = polygon_body()
|
|
240
|
+
body["task_views"][1]["description_fields"] = [field]
|
|
241
|
+
with pytest.raises(ImageContractError):
|
|
242
|
+
parse_image_schema_body(body)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
# --- Clip results ---------------------------------------------------------
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def obj(object_id, category, geometry):
|
|
249
|
+
return {
|
|
250
|
+
"id": object_id,
|
|
251
|
+
"image_id": "image_a",
|
|
252
|
+
"view_id": "objects",
|
|
253
|
+
"category_id": category,
|
|
254
|
+
"geometry": geometry,
|
|
255
|
+
"attributes": {},
|
|
256
|
+
"attribute_ranges": [],
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
BOX = {"geometry_type": "box_2d", "box": {"x_min": 10, "y_min": 20, "x_max": 30, "y_max": 40}}
|
|
261
|
+
POLY = polygon((100, 100), (300, 100), (200, 300))
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def text(text_id, target, field):
|
|
265
|
+
return {
|
|
266
|
+
"id": text_id,
|
|
267
|
+
"image_id": "image_a",
|
|
268
|
+
"view_id": "semantics",
|
|
269
|
+
"target_id": target,
|
|
270
|
+
"fields": {field: "text"},
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def clip(objects, descriptions=(), *, objects_state="complete", text_state="complete", body=None):
|
|
275
|
+
value = clip_payload()
|
|
276
|
+
record = parse_image_schema_record(
|
|
277
|
+
{
|
|
278
|
+
"contract_version": "x4d-image-label-schema-record-v1",
|
|
279
|
+
"status": "active",
|
|
280
|
+
"fingerprint": fingerprint(body or polygon_body()),
|
|
281
|
+
"body": body or polygon_body(),
|
|
282
|
+
}
|
|
283
|
+
)
|
|
284
|
+
value["label_schema"] = build_image_schema_snapshot(record)
|
|
285
|
+
value["image_annotation"]["objects"] = list(objects)
|
|
286
|
+
value["image_annotation"]["descriptions"] = list(descriptions)
|
|
287
|
+
states = {"objects": objects_state, "semantics": text_state}
|
|
288
|
+
for row in value["image_annotation"]["completion"]:
|
|
289
|
+
row["state"] = states[row["view_id"]]
|
|
290
|
+
value["identity"] = build_image_identity(value)
|
|
291
|
+
return parse_image_clip(value)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def test_box_and_polygon_share_a_category_and_ignore_is_polygon_only():
|
|
295
|
+
parsed = clip(
|
|
296
|
+
[obj("o1", "box", BOX), obj("o2", "box", POLY), obj("o3", "ignore", POLY)],
|
|
297
|
+
[text("p1", "o1", "phrase"), text("p2", "o2", "phrase"), text("c", None, "caption")],
|
|
298
|
+
)
|
|
299
|
+
stored = parsed.to_dict()["image_annotation"]["objects"]
|
|
300
|
+
assert stored[1]["geometry"] == POLY
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
@pytest.mark.parametrize(
|
|
304
|
+
"row",
|
|
305
|
+
[
|
|
306
|
+
obj("o1", "ignore", BOX),
|
|
307
|
+
obj("o1", "line", POLY),
|
|
308
|
+
{**obj("o1", "box", POLY), "attribute_ranges": [
|
|
309
|
+
{"range_id": "r", "start_vertex_id": "v0", "end_vertex_id": "v1", "attributes": {"x": True}}
|
|
310
|
+
]},
|
|
311
|
+
],
|
|
312
|
+
)
|
|
313
|
+
def test_object_geometry_must_be_allowed_by_its_category(row):
|
|
314
|
+
with pytest.raises(ImageContractError):
|
|
315
|
+
clip([row], text_state="unprocessed")
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def test_applicable_objects_require_the_conditional_caption():
|
|
319
|
+
objects = [obj("o1", "box", BOX), obj("o2", "ignore", POLY)]
|
|
320
|
+
clip(objects, [text("p1", "o1", "phrase"), text("c", None, "caption")])
|
|
321
|
+
with pytest.raises(ImageContractError) as error:
|
|
322
|
+
clip(objects, [text("p1", "o1", "phrase")])
|
|
323
|
+
assert error.value.code == "description_coverage_incomplete"
|
|
324
|
+
with pytest.raises(ImageContractError): # ignore regions cannot carry phrases
|
|
325
|
+
clip(objects, [text("p1", "o1", "phrase"), text("p2", "o2", "phrase"), text("c", None, "caption")])
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def test_ignore_only_image_completes_text_without_the_inapplicable_caption():
|
|
329
|
+
objects = [obj("o2", "ignore", POLY)]
|
|
330
|
+
clip(objects, [])
|
|
331
|
+
with pytest.raises(ImageContractError) as error:
|
|
332
|
+
clip(objects, [text("c", None, "caption")])
|
|
333
|
+
assert error.value.code == "description_not_applicable"
|
|
334
|
+
# Drafts may hold a stale caption until the scope is completed.
|
|
335
|
+
clip(objects, [text("c", None, "caption")], text_state="unprocessed")
|
|
336
|
+
clip(objects, [], text_state="confirmed_empty")
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def test_empty_image_keeps_the_existing_caption_flow():
|
|
340
|
+
clip([], [text("c", None, "caption")], objects_state="confirmed_empty")
|
|
341
|
+
with pytest.raises(ImageContractError) as error:
|
|
342
|
+
clip([], [], objects_state="confirmed_empty")
|
|
343
|
+
assert "confirm empty" in str(error.value)
|
|
344
|
+
clip([], [], objects_state="confirmed_empty", text_state="confirmed_empty")
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def test_fields_without_applies_when_keep_existing_behavior():
|
|
348
|
+
body = polygon_body()
|
|
349
|
+
del body["task_views"][1]["description_fields"][1]["applies_when"]
|
|
350
|
+
with pytest.raises(ImageContractError) as error:
|
|
351
|
+
clip([obj("o2", "ignore", POLY)], [], body=body)
|
|
352
|
+
assert "confirm empty" in str(error.value)
|
|
353
|
+
with pytest.raises(ImageContractError):
|
|
354
|
+
clip([obj("o2", "ignore", POLY)], [text("c", "o2", "phrase")], body=body)
|
|
355
|
+
clip([obj("o2", "ignore", POLY)], [text("c", None, "caption")], body=body)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
# --- explicit migration ---------------------------------------------------
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def test_box_only_clip_migrates_explicitly_to_box_or_polygon_categories():
|
|
362
|
+
source = clip_payload()
|
|
363
|
+
box = obj("box_a", "box", BOX)
|
|
364
|
+
source["image_annotation"]["objects"] = [box]
|
|
365
|
+
source["identity"] = build_image_identity(source)
|
|
366
|
+
body = polygon_body()
|
|
367
|
+
body["version"] = "2.0.0"
|
|
368
|
+
body["task_views"][1] = deepcopy(schema_body()["task_views"][1])
|
|
369
|
+
target = build_image_schema_snapshot(
|
|
370
|
+
parse_image_schema_record(
|
|
371
|
+
{
|
|
372
|
+
"contract_version": "x4d-image-label-schema-record-v1",
|
|
373
|
+
"status": "active",
|
|
374
|
+
"fingerprint": fingerprint(body),
|
|
375
|
+
"body": body,
|
|
376
|
+
}
|
|
377
|
+
)
|
|
378
|
+
)
|
|
379
|
+
mapping = {"contract_version": MAPPING_CONTRACT, "rules": []}
|
|
380
|
+
migrated, report = image_schema_migration_candidate(source, target, mapping)
|
|
381
|
+
after = migrated.to_dict()
|
|
382
|
+
assert after["image_annotation"] == source["image_annotation"]
|
|
383
|
+
assert report["changes"] == []
|
|
384
|
+
build_image_schema_migration_preview(source, target, mapping)
|
|
385
|
+
|
|
386
|
+
narrowed = deepcopy(body)
|
|
387
|
+
narrowed["categories"][1]["geometry_type"] = "polygon_2d"
|
|
388
|
+
del narrowed["categories"][1]["geometry_types"]
|
|
389
|
+
narrowed_target = build_image_schema_snapshot(
|
|
390
|
+
parse_image_schema_record(
|
|
391
|
+
{
|
|
392
|
+
"contract_version": "x4d-image-label-schema-record-v1",
|
|
393
|
+
"status": "active",
|
|
394
|
+
"fingerprint": fingerprint(narrowed),
|
|
395
|
+
"body": narrowed,
|
|
396
|
+
}
|
|
397
|
+
)
|
|
398
|
+
)
|
|
399
|
+
with pytest.raises(ImageSchemaMigrationConflict) as caught:
|
|
400
|
+
image_schema_migration_candidate(source, narrowed_target, mapping)
|
|
401
|
+
assert [row["code"] for row in caught.value.conflicts] == ["object_unrepresentable"]
|
|
@@ -313,6 +313,11 @@ def test_service_is_ready_with_one_model_and_explicit_task_outputs():
|
|
|
313
313
|
"max_concurrent_tasks": 1,
|
|
314
314
|
}
|
|
315
315
|
assert parse_image_preannotation_service(value).to_dict() == value
|
|
316
|
+
polygons = {**value, "outputs": [{"category_id": "line", "geometry_type": "polygon_2d"}]}
|
|
317
|
+
parse_image_preannotation_service(polygons)
|
|
318
|
+
polygons["outputs"] = [{"category_id": "line", "geometry_type": "mask_2d"}]
|
|
319
|
+
with pytest.raises(ValueError):
|
|
320
|
+
parse_image_preannotation_service(polygons)
|
|
316
321
|
value["task_ids"] *= 2
|
|
317
322
|
with pytest.raises(ValueError):
|
|
318
323
|
parse_image_preannotation_service(value)
|
|
@@ -11,7 +11,7 @@ from x4d_devkit.eval.matching import MetricData
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def test_package_version_is_current_release():
|
|
14
|
-
assert x4d_devkit.__version__ == "0.
|
|
14
|
+
assert x4d_devkit.__version__ == "0.57.0"
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def test_loader_exposes_and_enforces_only_current_schema(tmp_path):
|
|
@@ -26,7 +26,10 @@ from x4d_devkit._image_contract import (
|
|
|
26
26
|
)
|
|
27
27
|
from x4d_devkit.image_geometry import parse_image_attribute_ranges, parse_image_geometry
|
|
28
28
|
from x4d_devkit.image_groups import validate_image_object_groups
|
|
29
|
-
from x4d_devkit.image_schema import
|
|
29
|
+
from x4d_devkit.image_schema import (
|
|
30
|
+
image_category_geometry_types,
|
|
31
|
+
parse_image_schema_snapshot,
|
|
32
|
+
)
|
|
30
33
|
|
|
31
34
|
|
|
32
35
|
IMAGE_CLIP_CONTRACT_VERSION = "x4d-image-clip-v1"
|
|
@@ -304,16 +307,32 @@ def _completed_rules(values: dict, category: dict, path: str) -> None:
|
|
|
304
307
|
)
|
|
305
308
|
|
|
306
309
|
|
|
310
|
+
def _applicable(view: dict, row: dict) -> bool:
|
|
311
|
+
return not view["category_ids"] or row["category_id"] in view["category_ids"]
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def _field_applies(item: dict, view: dict, present: frozenset) -> bool:
|
|
315
|
+
"""An ``applies_when: applicable_objects`` image field does not apply only
|
|
316
|
+
when the image has objects (``present`` category IDs) and none of them is
|
|
317
|
+
in the view's categories. Images without objects keep today's flow."""
|
|
318
|
+
|
|
319
|
+
if "applies_when" not in item:
|
|
320
|
+
return True
|
|
321
|
+
return (
|
|
322
|
+
not present
|
|
323
|
+
or not view["category_ids"]
|
|
324
|
+
or not present.isdisjoint(view["category_ids"])
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
|
|
307
328
|
def _description_coverage(
|
|
308
|
-
image_id: str, view: dict, objects: dict, described:
|
|
329
|
+
image_id: str, view: dict, objects: dict, described: dict, present: frozenset
|
|
309
330
|
) -> None:
|
|
310
331
|
targets = {item.get("target") for item in view["description_fields"]}
|
|
311
332
|
path = f"image_annotation.completion.{image_id}.{view['id']}"
|
|
312
333
|
if "object" in targets:
|
|
313
334
|
for name, row in sorted(objects.items()):
|
|
314
|
-
if row["image_id"] != image_id or (
|
|
315
|
-
view["category_ids"] and row["category_id"] not in view["category_ids"]
|
|
316
|
-
):
|
|
335
|
+
if row["image_id"] != image_id or not _applicable(view, row):
|
|
317
336
|
continue
|
|
318
337
|
if (view["id"], image_id, name) not in described:
|
|
319
338
|
raise ImageContractError(
|
|
@@ -321,7 +340,21 @@ def _description_coverage(
|
|
|
321
340
|
message="every applicable object requires its description",
|
|
322
341
|
path=path + "." + name,
|
|
323
342
|
)
|
|
324
|
-
|
|
343
|
+
image_fields = [
|
|
344
|
+
item for item in view["description_fields"] if item.get("target") == "image"
|
|
345
|
+
]
|
|
346
|
+
applying = [
|
|
347
|
+
item for item in image_fields if _field_applies(item, view, present)
|
|
348
|
+
]
|
|
349
|
+
values = described.get((view["id"], image_id, None))
|
|
350
|
+
for item in image_fields:
|
|
351
|
+
if item not in applying and values is not None and item["id"] in values:
|
|
352
|
+
raise ImageContractError(
|
|
353
|
+
code="description_not_applicable",
|
|
354
|
+
message="the image has no applicable objects for this field",
|
|
355
|
+
path=path + "." + item["id"],
|
|
356
|
+
)
|
|
357
|
+
if applying and values is None:
|
|
325
358
|
raise ImageContractError(
|
|
326
359
|
code="description_coverage_incomplete",
|
|
327
360
|
message="the completed image requires its image description",
|
|
@@ -329,6 +362,22 @@ def _description_coverage(
|
|
|
329
362
|
)
|
|
330
363
|
|
|
331
364
|
|
|
365
|
+
def _inapplicable_description_scope(view: dict, present: frozenset) -> bool:
|
|
366
|
+
"""A description scope that may be complete without results: every
|
|
367
|
+
image-target field is conditional and inapplicable to this image."""
|
|
368
|
+
|
|
369
|
+
image_fields = [
|
|
370
|
+
item for item in view["description_fields"] if item.get("target") == "image"
|
|
371
|
+
]
|
|
372
|
+
return (
|
|
373
|
+
view["kind"] == "descriptions"
|
|
374
|
+
and bool(image_fields)
|
|
375
|
+
and all(
|
|
376
|
+
not _field_applies(item, view, present) for item in image_fields
|
|
377
|
+
)
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
|
|
332
381
|
def validate_image_annotations(
|
|
333
382
|
value: Any, *, clip_id: str, images: dict, schema: dict, view_ids: list[str]
|
|
334
383
|
) -> ImageDocument:
|
|
@@ -415,8 +464,8 @@ def _validate_annotations(
|
|
|
415
464
|
row["geometry"], width=image["width"], height=image["height"]
|
|
416
465
|
)
|
|
417
466
|
require(
|
|
418
|
-
geometry.geometry_type
|
|
419
|
-
"geometry
|
|
467
|
+
geometry.geometry_type in image_category_geometry_types(category),
|
|
468
|
+
"geometry is not allowed by the category",
|
|
420
469
|
path + ".geometry",
|
|
421
470
|
)
|
|
422
471
|
_attributes(
|
|
@@ -454,7 +503,7 @@ def _validate_annotations(
|
|
|
454
503
|
else:
|
|
455
504
|
require(
|
|
456
505
|
row["attribute_ranges"] == [],
|
|
457
|
-
"
|
|
506
|
+
"only polylines carry segment ranges",
|
|
458
507
|
path + ".attribute_ranges",
|
|
459
508
|
)
|
|
460
509
|
occupied.add((row["image_id"], row["view_id"]))
|
|
@@ -465,7 +514,14 @@ def _validate_annotations(
|
|
|
465
514
|
categories=categories,
|
|
466
515
|
result_ids=set(objects) | set(descriptions),
|
|
467
516
|
)
|
|
468
|
-
|
|
517
|
+
by_image: dict[str, set[str]] = {}
|
|
518
|
+
for row in objects.values():
|
|
519
|
+
by_image.setdefault(row["image_id"], set()).add(row["category_id"])
|
|
520
|
+
|
|
521
|
+
def present(image_id: str) -> frozenset:
|
|
522
|
+
return frozenset(by_image.get(image_id, ()))
|
|
523
|
+
|
|
524
|
+
described: dict[tuple, dict] = {}
|
|
469
525
|
for name, row in descriptions.items():
|
|
470
526
|
path = "image_annotation.descriptions." + name
|
|
471
527
|
fields(row, {"id", "image_id", "view_id", "target_id", "fields"}, path)
|
|
@@ -519,7 +575,7 @@ def _validate_annotations(
|
|
|
519
575
|
"duplicate description for the same target",
|
|
520
576
|
path + ".target_id",
|
|
521
577
|
)
|
|
522
|
-
described
|
|
578
|
+
described[key] = row["fields"]
|
|
523
579
|
for key, item in values.items():
|
|
524
580
|
require(
|
|
525
581
|
type(item) is str and bool(item.strip()),
|
|
@@ -528,7 +584,9 @@ def _validate_annotations(
|
|
|
528
584
|
)
|
|
529
585
|
require(
|
|
530
586
|
all(
|
|
531
|
-
not item["required"]
|
|
587
|
+
not item["required"]
|
|
588
|
+
or key in values
|
|
589
|
+
or not _field_applies(item, view, present(row["image_id"]))
|
|
532
590
|
for key, item in definitions.items()
|
|
533
591
|
),
|
|
534
592
|
"missing required description",
|
|
@@ -561,7 +619,11 @@ def _validate_annotations(
|
|
|
561
619
|
"image_annotation.completion",
|
|
562
620
|
)
|
|
563
621
|
require(
|
|
564
|
-
row["state"] != "complete"
|
|
622
|
+
row["state"] != "complete"
|
|
623
|
+
or pair in occupied
|
|
624
|
+
or _inapplicable_description_scope(
|
|
625
|
+
views[row["view_id"]], present(row["image_id"])
|
|
626
|
+
),
|
|
565
627
|
"empty completed scope must explicitly confirm empty",
|
|
566
628
|
"image_annotation.completion",
|
|
567
629
|
)
|
|
@@ -585,7 +647,9 @@ def _validate_annotations(
|
|
|
585
647
|
for image_id, view_id in sorted(complete):
|
|
586
648
|
view = views[view_id]
|
|
587
649
|
if view["kind"] == "descriptions":
|
|
588
|
-
_description_coverage(
|
|
650
|
+
_description_coverage(
|
|
651
|
+
image_id, view, objects, described, present(image_id)
|
|
652
|
+
)
|
|
589
653
|
return document(value)
|
|
590
654
|
|
|
591
655
|
|