Skip to content

Commit 853607d

Browse files
feat: added tracking stage, per-session logic, optimal detection pairing
1 parent e06f79f commit 853607d

File tree

5 files changed

+277
-59
lines changed

5 files changed

+277
-59
lines changed

ami/jobs/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ami.jobs.tasks import run_job
1818
from ami.main.models import Deployment, Project, SourceImage, SourceImageCollection
1919
from ami.ml.models import Pipeline
20+
from ami.ml.tracking import perform_tracking_for_job
2021
from ami.utils.schemas import OrderedEnum
2122

2223
logger = logging.getLogger(__name__)
@@ -502,6 +503,7 @@ def run(cls, job: "Job"):
502503
status=JobState.SUCCESS,
503504
progress=1,
504505
)
506+
perform_tracking_for_job(job)
505507
job.update_status(JobState.SUCCESS, save=False)
506508
job.finished_at = datetime.datetime.now()
507509
job.save()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 4.2.10 on 2025-05-29 16:21
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("main", "0066_alter_taxalist_projects_alter_taxon_projects_tag_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="detection",
15+
name="next_detection",
16+
field=models.OneToOneField(
17+
blank=True,
18+
help_text="The detection that follows this one in the tracking sequence.",
19+
null=True,
20+
on_delete=django.db.models.deletion.SET_NULL,
21+
related_name="previous_detection",
22+
to="main.detection",
23+
),
24+
),
25+
]

ami/main/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,14 @@ class Detection(BaseModel):
21372137
classifications: models.QuerySet["Classification"]
21382138
source_image_id: int
21392139
detection_algorithm_id: int
2140+
next_detection = models.OneToOneField(
2141+
"self",
2142+
on_delete=models.SET_NULL,
2143+
null=True,
2144+
blank=True,
2145+
related_name="previous_detection",
2146+
help_text="The detection that follows this one in the tracking sequence.",
2147+
)
21402148

21412149
# def bbox(self):
21422150
# return (

ami/ml/models/pipeline.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
SourceImageResponse,
4848
)
4949
from ami.ml.tasks import celery_app, create_detection_images
50-
from ami.ml.tracking import assign_occurrences_by_tracking
5150
from ami.utils.requests import create_session
5251

5352
logger = logging.getLogger(__name__)
@@ -882,14 +881,14 @@ def save_results(
882881

883882
# Create a new occurrence for each detection (no tracking yet)
884883
# @TODO remove when we implement tracking!
885-
# create_and_update_occurrences_for_detections(
886-
# detections=detections,
887-
# logger=job_logger,
888-
# )
889-
job_logger.info(f"Creating occurrences for {len(detections)} detections ")
890-
job_logger.info("type logger: " + str(type(job_logger)))
891-
892-
assign_occurrences_by_tracking(detections=detections, logger=job_logger)
884+
create_and_update_occurrences_for_detections(
885+
detections=detections,
886+
logger=job_logger,
887+
)
888+
# job_logger.info(f"Creating occurrences for {len(detections)} detections ")
889+
# check if every image in the sessions in processed
890+
891+
# assign_occurrences_by_tracking(detections=detections, logger=job_logger)
893892

894893
# Update precalculated counts on source images and events
895894
source_images = list(source_images)

0 commit comments

Comments
 (0)