Skip to content

Commit 7e8a27c

Browse files
authored
Merge pull request #312 from Mosquito-Alert/photoprediction_relative_bbox
Make photoprediction bbox to be relative
2 parents 783383c + 0d3915d commit 7e8a27c

File tree

11 files changed

+217
-54
lines changed

11 files changed

+217
-54
lines changed

api/tests/integration/identification_tasks/predictions/create.tavern.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ stages:
6262
bbox:
6363
x_min: 0
6464
y_min: 0
65-
x_max: 50
66-
y_max: 50
65+
x_max: 0.50
66+
y_max: 0.50
6767
insect_confidence: 0.9
6868
predicted_class: 'ae_albopictus'
6969
threshold_deviation: 0.9
@@ -87,8 +87,8 @@ stages:
8787
bbox:
8888
x_min: 0
8989
y_min: 0
90-
x_max: 50
91-
y_max: 50
90+
x_max: 0.5
91+
y_max: 0.5
9292
insect_confidence: 0.9
9393
predicted_class: 'ae_albopictus'
9494
is_decisive: false

api/tests/integration/identification_tasks/predictions/factories.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_photo_prediction(photo: Photo) -> PhotoPrediction:
3838
other_species_score=0.01,
3939
not_sure_score=0,
4040
x_tl=0,
41-
x_br=photo.photo.width / 2,
41+
x_br=0.5,
4242
y_tl=0,
43-
y_br=photo.photo.height / 2
43+
y_br=0.5
4444
)

api/tests/integration/identification_tasks/predictions/schema.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ variables:
99
uuid: !anystr
1010
url: !anystr
1111
bbox:
12-
x_min: !anyint
13-
y_min: !anyint
14-
x_max: !anyint
15-
y_max: !anyint
12+
x_min: !anyfloat
13+
y_min: !anyfloat
14+
x_max: !anyfloat
15+
y_max: !anyfloat
1616
insect_confidence: !anyfloat
1717
predicted_class: !anystr
1818
is_decisive: !anybool

api/tests/integration/identification_tasks/predictions/update.tavern.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ stages:
3939
method: "{method}"
4040
json:
4141
bbox:
42-
x_min: 50
43-
y_min: 50
44-
x_max: 51
45-
y_max: 51
42+
x_min: 0.50
43+
y_min: 0.50
44+
x_max: 0.51
45+
y_max: 0.51
4646
insect_confidence: 0.2
4747
predicted_class: 'not_sure'
4848
threshold_deviation: 0.9
@@ -88,10 +88,10 @@ stages:
8888
method: "{method}"
8989
json:
9090
bbox:
91-
x_min: 50
92-
y_min: 50
93-
x_max: 51
94-
y_max: 51
91+
x_min: 0.50
92+
y_min: 0.50
93+
x_max: 0.51
94+
y_max: 0.51
9595
insect_confidence: 0.2
9696
predicted_class: 'not_sure'
9797
threshold_deviation: 0.9
@@ -115,10 +115,10 @@ stages:
115115
uuid: "{photo_prediction.photo.uuid}"
116116
url: !anystr
117117
bbox:
118-
x_min: 50
119-
y_min: 50
120-
x_max: 51
121-
y_max: 51
118+
x_min: 0.50
119+
y_min: 0.50
120+
x_max: 0.51
121+
y_max: 0.51
122122
insect_confidence: 0.2
123123
predicted_class: 'not_sure'
124124
threshold_deviation: 0.9

api/tests/integration/photos/predictions/schema.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ variables:
99
uuid: !anystr
1010
url: !anystr
1111
bbox:
12-
x_min: !anyint
13-
y_min: !anyint
14-
x_max: !anyint
15-
y_max: !anyint
12+
x_min: !anyfloat
13+
y_min: !anyfloat
14+
x_max: !anyfloat
15+
y_max: !anyfloat
1616
insect_confidence: !anyfloat
1717
predicted_class: !anystr
1818
is_decisive: !anybool

api/tests/integration/photos/predictions/update.tavern.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ stages:
3939
method: "{method}"
4040
json:
4141
bbox:
42-
x_min: 50
43-
y_min: 50
44-
x_max: 51
45-
y_max: 51
42+
x_min: 0.50
43+
y_min: 0.50
44+
x_max: 0.51
45+
y_max: 0.51
4646
insect_confidence: 0.2
4747
predicted_class: 'not_sure'
4848
threshold_deviation: 0.9
@@ -66,10 +66,10 @@ stages:
6666
uuid: "{photo_prediction.photo.uuid}"
6767
url: !anystr
6868
bbox:
69-
x_min: 50
70-
y_min: 50
71-
x_max: 51
72-
y_max: 51
69+
x_min: 0.50
70+
y_min: 0.50
71+
x_max: 0.51
72+
y_max: 0.51
7373
insect_confidence: 0.2
7474
predicted_class: 'not_sure'
7575
threshold_deviation: 0.9
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 3.2.25 on 2025-06-16 14:45
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('tigacrafting', '0034_auto_20250616_1427'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='photoprediction',
16+
name='height',
17+
field=models.PositiveIntegerField(default=0),
18+
preserve_default=False,
19+
),
20+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 3.2.25 on 2025-06-16 14:45
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('tigacrafting', '0035_photoprediction_height_default_0'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='photoprediction',
16+
name='width',
17+
field=models.PositiveIntegerField(default=0),
18+
preserve_default=False,
19+
),
20+
]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Generated by Django 3.2.25 on 2025-06-16 14:46
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
from django.db.models import F, Case, When, Value, FloatField
6+
7+
def convert_bbox_to_relative(apps, schema_editor):
8+
PhotoPrediction = apps.get_model('tigacrafting', 'PhotoPrediction')
9+
10+
PhotoPrediction.objects.update(
11+
x_tl=Case(
12+
When(width=0, then=Value(0)),
13+
default=F('x_tl') / F('width'),
14+
output_field=FloatField()
15+
),
16+
x_br=Case(
17+
When(width=0, then=Value(0)),
18+
default=F('x_br') / F('width'),
19+
output_field=FloatField()
20+
),
21+
y_tl=Case(
22+
When(height=0, then=Value(0)),
23+
default=F('y_tl') / F('height'),
24+
output_field=FloatField()
25+
),
26+
y_br=Case(
27+
When(height=0, then=Value(0)),
28+
default=F('y_br') / F('height'),
29+
output_field=FloatField()
30+
),
31+
)
32+
33+
def convert_bbox_to_absolute(apps, schema_editor):
34+
PhotoPrediction = apps.get_model('tigacrafting', 'PhotoPrediction')
35+
PhotoPrediction.objects.update(
36+
x_tl=models.F('x_tl') * models.F('width'),
37+
x_br=models.F('x_br') * models.F('width'),
38+
y_tl=models.F('y_tl') * models.F('height'),
39+
y_br=models.F('y_br') * models.F('height'),
40+
)
41+
42+
class Migration(migrations.Migration):
43+
44+
dependencies = [
45+
('tigacrafting', '0036_photoprediction_width_default_0'),
46+
]
47+
48+
operations = [
49+
migrations.AlterField(
50+
model_name='photoprediction',
51+
name='x_br',
52+
field=models.FloatField(help_text='photo bounding box relative coordinates bottom right x', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)]),
53+
),
54+
migrations.AlterField(
55+
model_name='photoprediction',
56+
name='x_tl',
57+
field=models.FloatField(help_text='photo bounding box relative coordinates top left x', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)]),
58+
),
59+
migrations.AlterField(
60+
model_name='photoprediction',
61+
name='y_br',
62+
field=models.FloatField(help_text='photo bounding box relative coordinates bottom right y', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)]),
63+
),
64+
migrations.AlterField(
65+
model_name='photoprediction',
66+
name='y_tl',
67+
field=models.FloatField(help_text='photo bounding box relative coordinates top left y', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)]),
68+
),
69+
migrations.RunPython(convert_bbox_to_relative, convert_bbox_to_absolute)
70+
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 3.2.25 on 2025-06-16 14:46
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tigacrafting', '0037_populate_bbox_relative'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='photoprediction',
15+
name='height',
16+
),
17+
migrations.RemoveField(
18+
model_name='photoprediction',
19+
name='width',
20+
),
21+
migrations.AddConstraint(
22+
model_name='photoprediction',
23+
constraint=models.CheckConstraint(check=models.Q(('x_tl__range', (0, 1))), name='tigacrafting_photoprediction_x_tl_between_0_and_1'),
24+
),
25+
migrations.AddConstraint(
26+
model_name='photoprediction',
27+
constraint=models.CheckConstraint(check=models.Q(('x_br__range', (0, 1))), name='tigacrafting_photoprediction_x_br_between_0_and_1'),
28+
),
29+
migrations.AddConstraint(
30+
model_name='photoprediction',
31+
constraint=models.CheckConstraint(check=models.Q(('y_tl__range', (0, 1))), name='tigacrafting_photoprediction_y_tl_between_0_and_1'),
32+
),
33+
migrations.AddConstraint(
34+
model_name='photoprediction',
35+
constraint=models.CheckConstraint(check=models.Q(('y_br__range', (0, 1))), name='tigacrafting_photoprediction_y_br_between_0_and_1'),
36+
),
37+
]

0 commit comments

Comments
 (0)