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

Reintroduce Face Classification #1418

Merged
merged 18 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Imporve handling of classification mode
  • Loading branch information
derneuere committed Oct 8, 2024
commit f5927dce6e7a59674aeee1738eb268b0d2ea7568
5 changes: 4 additions & 1 deletion api/serializers/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Meta:
]

def get_person_label_probability(self, obj):
return obj.cluster_probability
if obj.analysis_method == "clustering":
return obj.cluster_probability
else:
return obj.classification_probability

def get_face_url(self, obj):
return obj.image.url
Expand Down
34 changes: 23 additions & 11 deletions api/views/faces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid

from django.db.models import Case, Count, IntegerField, Q, When
from django.db.models import Case, CharField, Count, IntegerField, Q, Value, When
from django_q.tasks import Chain
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, extend_schema
Expand Down Expand Up @@ -73,30 +73,40 @@ class FaceListView(ListViewSet):

def get_queryset(self):
personid = self.request.query_params.get("person")
order_by = ["-cluster_probability", "id"]

conditional_filter = Q(person=personid)
analysis_method = self.request.query_params.get("analysis_method", "clustering")
if (
self.request.query_params.get("inferred")
and self.request.query_params.get("inferred").lower() == "true"
):
if analysis_method == "classification":
conditional_filter = Q(classification_person=personid)
conditional_filter = Q(classification_person=personid) & Q(person=None)
order_by = ["-classification_probability", "id"]
if analysis_method == "clustering":
conditional_filter = Q(cluster_person=personid)
conditional_filter = Q(cluster_person=personid) & Q(person=None)
order_by = ["-cluster_probability", "id"]
if self.request.query_params.get("order_by"):
if self.request.query_params.get("order_by").lower() == "date":
order_by = [
"photo__exif_timestamp",
"-cluster_probability",
"id",
]
if analysis_method == "classification":
order_by = [
"photo__exif_timestamp",
"-classification_probability",
"id",
]
if analysis_method == "clustering":
order_by = [
"photo__exif_timestamp",
"-cluster_probability",
"id",
]
return (
Face.objects.filter(
Q(photo__owner=self.request.user),
Q(deleted=False),
conditional_filter,
)
.annotate(analysis_method=Value(analysis_method, output_field=CharField()))
.prefetch_related("photo")
.order_by(*order_by)
)
Expand Down Expand Up @@ -126,7 +136,8 @@ def get_queryset(self):
conditional_count = Count(
Case(
When(
Q(classification_faces__deleted=False),
Q(classification_faces__deleted=False)
& Q(classification_faces__person=None),
then=1,
),
output_field=IntegerField(),
Expand All @@ -136,7 +147,8 @@ def get_queryset(self):
conditional_count = Count(
Case(
When(
Q(cluster_faces__deleted=False),
Q(cluster_faces__deleted=False)
& Q(cluster_faces__person=None),
then=1,
),
output_field=IntegerField(),
Expand Down