Skip to content
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

Initial methods to skip already-processed images. #374

Merged
merged 9 commits into from
Apr 1, 2024
2 changes: 1 addition & 1 deletion ami/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __str__(self) -> str:
"""All django models should have this method."""
if hasattr(self, "name"):
name = getattr(self, "name") or "Untitled"
return name
return f"#{self.pk} {name}"
else:
return f"{self.__class__.__name__} #{self.pk}"

Expand Down
5 changes: 3 additions & 2 deletions ami/jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def run(self):
deployment=self.deployment,
source_images=[self.source_image_single] if self.source_image_single else None,
job_id=self.pk,
skip_processed=True,
# shuffle=self.shuffle,
)
)
Expand Down Expand Up @@ -447,12 +448,12 @@ def run(self):
continue

total_detections += len(results.detections)
total_classifications += len(results.classifications)
total_classifications += len([c for d in results.detections for c in d.classifications])
self.progress.update_stage(
"process",
status=JobState.STARTED,
progress=(i + 1) / len(chunks),
proccessed=(i + 1) * CHUNK_SIZE,
processed=(i + 1) * CHUNK_SIZE,
remaining=image_count - (i + 1) * CHUNK_SIZE,
detections=total_detections,
classifications=total_classifications,
Expand Down
2 changes: 1 addition & 1 deletion ami/main/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def get_queryset(self) -> QuerySet:
.filter(has_detections=has_detections)
.order_by(
"?"
) # Random order is here for our demo ML backend to limit the same images from being proccessed
) # Random order is here for our demo ML backend to limit the same images from being processed
# @TODO remove this when we have a real queue for the ML backend
)
return queryset
Expand Down
6 changes: 6 additions & 0 deletions ami/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,9 @@ class Classification(BaseModel):
class Meta:
ordering = ["-created_at", "-score"]

def __str__(self) -> str:
return f"#{self.pk} to Taxon #{self.taxon_id} ({self.score:.2f}) by Algorithm #{self.algorithm_id}"


@final
class Detection(BaseModel):
Expand Down Expand Up @@ -1538,6 +1541,9 @@ def save(self, update_calculated_fields=True, *args, **kwargs):
# if not self.occurrence:
# self.associate_new_occurrence()

def __str__(self) -> str:
return f"#{self.pk} from SourceImage #{self.source_image_id} with Algorithm #{self.detection_algorithm_id}"


@final
class OccurrenceManager(models.Manager):
Expand Down
4 changes: 3 additions & 1 deletion ami/ml/models/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

if TYPE_CHECKING:
from ami.main.models import Classification
from ami.ml.models import Pipeline

import typing

Expand All @@ -22,11 +23,12 @@ class Algorithm(BaseModel):
description = models.TextField(blank=True)
version = models.IntegerField(default=1)
version_name = models.CharField(max_length=255, blank=True)
url = models.URLField(blank=True)
url = models.URLField(blank=True) # URL to the model homepage, origin or docs (huggingface, wandb, etc.)

# api_base_url = models.URLField(blank=True)
# api = models.CharField(max_length=255, blank=True)

pipelines: models.QuerySet[Pipeline]
classifications: models.QuerySet[Classification]

class Meta:
Expand Down
Loading