-
Notifications
You must be signed in to change notification settings - Fork 11
Auto-process manually uploaded images (if enabled) #909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
29979ec
feat: clean up when events are regrouped for a deployment
mihow 2b8f78d
feat: add created & updated at columns to sessions/events list
mihow 32fc496
feat: configure default related models with new projects
mihow ad26bb5
feat: allow specifying which pipelines are enabled by default
mihow bcf205c
feat: add denmark/uk model to default pipelines
mihow c00f6a7
feat: add tests for default enabled pipelines
mihow 27cb97e
chore: rename default station
mihow 49d6e47
fix: undefined variables in certain cases
mihow 34badc1
chore: cleanup typos and comments
mihow d4f7047
fix: update default sampling method for collections
mihow 8b9a3a8
Configure default related models for new projects (#905)
mihow 747ebad
feat: process images immediately after uploading (prototype)
mihow e984197
feat: read timestamp from EXIF data in special cases
mihow efcadda
Merge branch 'main' of github.com:RolnickLab/antenna into feat/quicks…
mihow e18e37a
chore: clean up comments and unused
mihow 28352de
feat: query method to select pipelines enabled for project
mihow e29c16e
feat: process_single_image function in a new home
mihow e7df08c
fix: default pipeline query
mihow 84dc4a4
feat: fallback to the current datetime for test uploads
mihow 978ef0d
chore: disable auto-processing manual uploads by default
mihow f5c55b8
fix: cleanup
mihow 346a9c3
Merge branch 'main' of github.com:RolnickLab/antenna into feat/quicks…
mihow 50999d5
chore: cleanup
mihow 76ac612
fix: remove duplicate migration after merge
mihow 5d2294b
fix: select only pipelines with an avail processor for the project
mihow b49666b
feat: move the create method to the view
mihow 7fc8c59
fix: allow the current project to be passed in post / form data
mihow b5be1f7
feat: require project in source image upload
mihow 306252a
feat: use project feature flag for auto processing
mihow 6c03080
fix: pass project ID when creating source image in test
mihow 6a35c10
fix: separate titles for source images & source image collections
mihow 2d44bf2
fix: typo in property name, require projects for source image uploads
mihow 6bc4cad
Merge branch 'main' of github.com:RolnickLab/antenna into feat/quicks…
mihow a82078b
feat: use default pipeline in project settings first
mihow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
ami/main/migrations/0061_alter_sourceimagecollection_method.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Generated by Django 4.2.10 on 2025-07-24 21:26 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("main", "0060_alter_sourceimagecollection_method"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name="sourceimagecollection", | ||
| name="method", | ||
| field=models.CharField( | ||
| choices=[ | ||
| ("full", "full"), | ||
| ("random", "random"), | ||
| ("stratified_random", "stratified_random"), | ||
| ("interval", "interval"), | ||
| ("manual", "manual"), | ||
| ("starred", "starred"), | ||
| ("random_from_each_event", "random_from_each_event"), | ||
| ("last_and_random_from_each_event", "last_and_random_from_each_event"), | ||
| ("greatest_file_size_from_each_event", "greatest_file_size_from_each_event"), | ||
| ("detections_only", "detections_only"), | ||
| ("common_combined", "common_combined"), | ||
| ], | ||
| default="full", | ||
| max_length=255, | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .processing import * # noqa: F401, F403 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from django.db import models | ||
|
|
||
| from ami.main.models import Project | ||
| from ami.ml.models.pipeline import Pipeline | ||
|
|
||
|
|
||
| def get_default_pipeline(project: Project) -> Pipeline | None: | ||
| """ | ||
| Select a default pipeline to use for processing images in a project. | ||
|
|
||
| This is a placeholder function that selects the pipeline with the most categories | ||
| and which is enabled for the project. | ||
|
|
||
| @TODO use project settings to determine the default pipeline | ||
| """ | ||
| return ( | ||
| Pipeline.objects.all() | ||
| .enabled(project=project) # type: ignore | ||
| .annotate(num_categories=models.Count("algorithms__category_map__labels")) | ||
| .order_by("-num_categories", "-created_at") | ||
| .first() | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import typing | ||
|
|
||
| from ami.jobs.models import Job | ||
| from ami.ml.models import Pipeline | ||
| from ami.ml.orchestration.pipelines import get_default_pipeline | ||
|
|
||
| if typing.TYPE_CHECKING: | ||
| from ami.main.models import SourceImage | ||
|
|
||
|
|
||
| def process_single_source_image( | ||
| source_image: "SourceImage", | ||
| pipeline: "Pipeline | None" = None, | ||
| run_async=True, | ||
| ) -> "Job": | ||
| """ | ||
| Process a single SourceImage immediately. | ||
| """ | ||
|
|
||
| assert source_image.deployment is not None, "SourceImage must belong to a deployment" | ||
|
|
||
| if not source_image.event: | ||
| source_image.deployment.save(regroup_async=False) | ||
| source_image.refresh_from_db() | ||
| assert source_image.event is not None, "SourceImage must belong to an event" | ||
|
|
||
| project = source_image.project | ||
| assert project is not None, "SourceImage must belong to a project" | ||
|
|
||
| pipeline_choice = pipeline or get_default_pipeline(project) | ||
| assert pipeline_choice is not None, "Project must have a pipeline to run" | ||
|
|
||
| # @TODO add images to a queue without creatin a job for each image | ||
mihow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| job = Job.objects.create( | ||
| name=f"Capture #{source_image.pk} ({source_image.timestamp}) from {source_image.deployment.name}", | ||
| job_type_key="ml", | ||
| source_image_single=source_image, | ||
| pipeline=pipeline_choice, | ||
| project=project, | ||
| ) | ||
| if run_async: | ||
| job.enqueue() | ||
| else: | ||
| job.run() | ||
| return job | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.