Приложение: FastAPI-фабрика, ядро DINOv2 (torch.hub ViT-S/14, CLS-эмбеддинги), POST /api/v1/verify
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""Pydantic-схемы JSON-ответов (вход — multipart, разбирается вручную)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Thresholds(BaseModel):
|
||||
match: float = Field(description="Порог best_similarity >= X -> match")
|
||||
no_match: float = Field(description="Порог best_similarity < X -> no_match")
|
||||
|
||||
|
||||
class VerifyDetails(BaseModel):
|
||||
references_compared: int = Field(description="Сколько эталонов сравнено")
|
||||
best_reference_index: int = Field(description="Индекс лучшего эталона (0-based)")
|
||||
best_similarity: float = Field(description="Лучшая косинусная близость")
|
||||
similarities: List[float] = Field(description="Близости к каждому эталону по порядку")
|
||||
thresholds: Thresholds
|
||||
|
||||
|
||||
class VerifyResponse(BaseModel):
|
||||
verdict: Literal["match", "uncertain", "no_match"] = Field(
|
||||
description="match — то же здание/памятник; no_match — другое; uncertain — между порогами"
|
||||
)
|
||||
is_match: bool = Field(description="Удобный флаг: verdict == match")
|
||||
confidence: float = Field(description="= best_similarity, косинусная близость 0..1")
|
||||
details: VerifyDetails
|
||||
probe_sha256: str = Field(description="SHA-256 проверяемого фото для аудита")
|
||||
processing_ms: float
|
||||
|
||||
|
||||
class ReadyResponse(BaseModel):
|
||||
status: Literal["ready", "unavailable"]
|
||||
reasons: List[str] = Field(default_factory=list, description="Причины неготовности")
|
||||
Reference in New Issue
Block a user