From 3c18921c470d937c8946b605729ee9e37a5b1977 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 17 Dec 2025 19:09:46 -0600 Subject: [PATCH] attributes endpoint --- frigate/api/classification.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/frigate/api/classification.py b/frigate/api/classification.py index deafaf956..ad0f84432 100644 --- a/frigate/api/classification.py +++ b/frigate/api/classification.py @@ -31,6 +31,7 @@ from frigate.api.defs.response.generic_response import GenericResponse from frigate.api.defs.tags import Tags from frigate.config import FrigateConfig from frigate.config.camera import DetectConfig +from frigate.config.classification import ObjectClassificationType from frigate.const import CLIPS_DIR, FACE_DIR, MODEL_CACHE_DIR from frigate.embeddings import EmbeddingsContext from frigate.models import Event @@ -622,6 +623,39 @@ def get_classification_dataset(name: str): ) +@router.get( + "/classification/attributes", + summary="Get all custom classification attributes", + description="""Returns a list of all unique attribute labels from custom classification models. + Only includes models with classification_type set to 'attribute'. + Optionally filter by object_type to only return attributes from models that apply to that object type.""", +) +def get_custom_attributes(request: Request, object_type: str = None): + custom_attribute_labels = set() + for name, model_config in request.app.frigate_config.classification.custom.items(): + if ( + model_config.object_config + and model_config.object_config.classification_type + == ObjectClassificationType.attribute + ): + # If object_type is specified, check if this model applies to that object type + if object_type is not None: + if ( + not hasattr(model_config.object_config, "objects") + or object_type not in model_config.object_config.objects + ): + continue + + dataset_dir = os.path.join(CLIPS_DIR, sanitize_filename(name), "dataset") + if os.path.exists(dataset_dir): + for category_name in os.listdir(dataset_dir): + category_dir = os.path.join(dataset_dir, category_name) + if os.path.isdir(category_dir): + custom_attribute_labels.add(category_name) + + return JSONResponse(content=sorted(list(custom_attribute_labels))) + + @router.get( "/classification/{name}/train", summary="Get classification train images",