Skip to content

Commit

Permalink
Add a quality setting for avoiding using bbox in point group matching
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max committed Nov 1, 2024
1 parent bce96ea commit 9605ac9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2024-11-01 11:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("quality_control", "0003_qualityreport_assignee_last_updated_and_more"),
]

operations = [
migrations.AddField(
model_name="qualitysettings",
name="use_image_space_for_point_group_comparisons",
field=models.BooleanField(default=False),
),
]
2 changes: 2 additions & 0 deletions cvat/apps/quality_control/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class QualitySettings(models.Model):

low_overlap_threshold = models.FloatField()

use_image_space_for_point_group_comparisons = models.BooleanField(default=False)

compare_line_orientation = models.BooleanField()
line_orientation_threshold = models.FloatField()

Expand Down
27 changes: 22 additions & 5 deletions cvat/apps/quality_control/quality_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class ComparisonParameters(_Serializable):
oks_sigma: float = 0.09
"Like IoU threshold, but for points, % of the bbox area to match a pair of points"

use_image_space_for_point_group_comparisons: bool = False
"Compare points in the image space, instead of using the point group bbox"

line_thickness: float = 0.01
"Thickness of polylines, relatively to the (image area) ^ 0.5"

Expand Down Expand Up @@ -955,6 +958,7 @@ def __init__(
# https://cocodataset.org/#keypoints-eval
# https://github.com/cocodataset/cocoapi/blob/8c9bcc3cf640524c4c20a9c40e89cb6a2f2fa0e9/PythonAPI/pycocotools/cocoeval.py#L523
oks_sigma: float = 0.09,
use_image_space_for_point_group_comparisons: bool = False,
compare_line_orientation: bool = False,
line_torso_radius: float = 0.01,
panoptic_comparison: bool = False,
Expand All @@ -968,6 +972,11 @@ def __init__(
self.oks_sigma = oks_sigma
"% of the shape area"

self.use_image_space_for_point_group_comparisons = (
use_image_space_for_point_group_comparisons
)
"Do not infer bbox for point group comparison, use the image space"

self.compare_line_orientation = compare_line_orientation
"Whether lines are oriented or not"

Expand Down Expand Up @@ -1293,13 +1302,18 @@ def _distance(a: dm.Points, b: dm.Points) -> float:
else:
# Complex case: multiple points, grouped points, points with a bbox
# Try to align points and then return the metric
# match them in their bbox space

if dm.ops.bbox_iou(a_bbox, b_bbox) <= 0:
return 0
if self.use_image_space_for_point_group_comparisons:
scale = img_h * img_w
else:
# match points in their bbox space

if dm.ops.bbox_iou(a_bbox, b_bbox) <= 0:
# this early exit may not work for points forming an axis-aligned line
return 0

bbox = dm.ops.mean_bbox([a_bbox, b_bbox])
scale = bbox[2] * bbox[3]
bbox = dm.ops.mean_bbox([a_bbox, b_bbox])
scale = bbox[2] * bbox[3]

a_points = np.reshape(a.points, (-1, 2))
b_points = np.reshape(b.points, (-1, 2))
Expand Down Expand Up @@ -1525,6 +1539,9 @@ def __init__(self, categories: dm.CategoriesInfo, *, settings: ComparisonParamet
panoptic_comparison=settings.panoptic_comparison,
iou_threshold=settings.iou_threshold,
oks_sigma=settings.oks_sigma,
use_image_space_for_point_group_comparisons=(
settings.use_image_space_for_point_group_comparisons
),
line_torso_radius=settings.line_thickness,
compare_line_orientation=False, # should not be taken from outside, handled differently
)
Expand Down
9 changes: 9 additions & 0 deletions cvat/apps/quality_control/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Meta:
"max_validations_per_job",
"iou_threshold",
"oks_sigma",
"use_image_space_for_point_group_comparisons",
"line_thickness",
"low_overlap_threshold",
"compare_line_orientation",
Expand All @@ -98,6 +99,9 @@ class Meta:
)

extra_kwargs = {k: {"required": False} for k in fields}
extra_kwargs.setdefault("use_image_space_for_point_group_comparisons", {}).setdefault(
"default", False
)

for field_name, help_text in {
"target_metric": "The primary metric used for quality estimation",
Expand All @@ -119,6 +123,11 @@ class Meta:
where the checked point is expected to be.
Read more: https://cocodataset.org/#keypoints-eval
""",
"use_image_space_for_point_group_comparisons": """
Compare point groups in the image space, instead of using the point group bbox.
Useful if point groups may not represent a single object or grouped boxes
do not represent object boundaries.
""",
"line_thickness": """
Thickness of polylines, relatively to the (image area) ^ 0.5.
The distance to the boundary around the GT line,
Expand Down

0 comments on commit 9605ac9

Please sign in to comment.