calibrate

This commit is contained in:
2026-10-06 17:58:35 +03:00
parent 86222f5f93
commit 476cfe0b17
21 changed files with 1666 additions and 14 deletions
+191 -1
View File
@@ -32,6 +32,8 @@ tags:
description: Извлечение признаков — один раз на эталонное фото
- name: verify
description: Верификация пробы по блобам/изображениям эталонов
- name: calibrate
description: Подбор per-объектных настроек сравнения по двум пачкам фото
- name: profiles
description: Каталог профилей настроек распознавания
- name: service
@@ -191,6 +193,87 @@ paths:
schema: {$ref: '#/components/schemas/ErrorResponse'}
'500': {$ref: '#/components/responses/Internal'}
/api/v1/calibrate:
post:
tags: [calibrate]
operationId: calibrateSettings
summary: Подобрать настройки сравнения под объект
description: |
Принимает две пачки фото и возвращает оптимальные параметры
**сравнения** для этого объекта: пачка `positive` — фото одного
объекта с разных ракурсов (≥ 2), пачка `negative` — фото других,
похожих объектов (≥ 1). Калибруются только параметры сравнения —
пересчёт эталонов не требуется; передайте выданный `settings`
в `/features` при регистрации эталонов и/или в `/verify`.
Битые файлы пропускаются и перечисляются в `skipped`; если после
отбраковки осталось < 2 позитивов или < 1 негатива —
422 CALIBRATION_DATASET_INVALID.
Тяжёлый синхронный запрос (stateless — фоновых задач нет):
до ~60 с при максимальных пачках 8+8. Настройте таймаут клиента
соответственно.
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
required: [positive, negative]
properties:
positive:
type: array
items: {type: string, format: binary}
minItems: 2
maxItems: 8
description: |
Фото одного объекта с разных ракурсов
(2…CALIBRATION_MAX_IMAGES_PER_PACK, по умолчанию 8).
Каждое — JPEG/PNG/WebP, ≤ MAX_IMAGE_MB, ≥ 640×480.
negative:
type: array
items: {type: string, format: binary}
minItems: 1
maxItems: 8
description: |
Фото других, похожих объектов (дистракторы) — по ним
калибруется защита от ложных срабатываний.
Лимиты части — как у positive.
Суммарный запрос ≤ CALIBRATION_MAX_BODY_MB (64 МБ).
encoding:
positive:
contentType: application/octet-stream
negative:
contentType: application/octet-stream
responses:
'200':
description: Полный отчёт калибровки; `settings` — готовый фрагмент для /features и /verify
content:
application/json:
schema: {$ref: '#/components/schemas/CalibrateResponse'}
'400':
description: |
TOO_MANY_CALIBRATION_IMAGES — фото в пачке больше
CALIBRATION_MAX_IMAGES_PER_PACK;
IMAGE_DECODE_FAILED/IMAGE_TOO_SMALL — возможны только в `skipped`
(битые файлы не валят запрос), в ответе 200.
content:
application/json:
schema: {$ref: '#/components/schemas/ErrorResponse'}
'401': {$ref: '#/components/responses/Unauthorized'}
'403': {$ref: '#/components/responses/Forbidden'}
'413': {$ref: '#/components/responses/PayloadTooLarge'}
'415': {$ref: '#/components/responses/UnsupportedMediaType'}
'422':
description: |
VALIDATION_ERROR — меньше 2 частей positive или 0 частей negative;
CALIBRATION_DATASET_INVALID — после отбраковки битых файлов
осталось < 2 позитивов или < 1 негатива.
content:
application/json:
schema: {$ref: '#/components/schemas/ErrorResponse'}
'500': {$ref: '#/components/responses/Internal'}
/api/v1/profiles:
get:
tags: [profiles]
@@ -264,7 +347,7 @@ components:
application/json:
schema: {$ref: '#/components/schemas/ErrorResponse'}
PayloadTooLarge:
description: PAYLOAD_TOO_LARGE — тело запроса сверх лимита (MAX_IMAGE_MB / VERIFY_MAX_BODY_MB)
description: PAYLOAD_TOO_LARGE — тело запроса сверх лимита (MAX_IMAGE_MB / VERIFY_MAX_BODY_MB / CALIBRATION_MAX_BODY_MB)
content:
application/json:
schema: {$ref: '#/components/schemas/ErrorResponse'}
@@ -437,6 +520,111 @@ components:
lowe_ratio: {type: number, example: 0.75}
ransac_reproj_threshold: {type: number, example: 5.0}
CalibrateResponse:
type: object
description: Полный отчёт калибровки (docs/05 §5.4.5)
required: [settings, metrics, best, ranking, pairs, presets, images, skipped, warnings, selfcheck, processing_ms]
properties:
settings:
type: object
description: |
Готовый фрагмент settings: `{"comparison": {...}}` в терминах
ComparisonSettings. Передайте его как form-часть settings
в /features (запишется в блоб эталона) и/или в /verify.
properties:
comparison: {$ref: '#/components/schemas/ComparisonSettings'}
metrics:
type: object
description: Метрики лучшей комбинации
properties:
f1: {type: number, description: F1 класса match}
true_matches: {type: integer, description: Позитивные пары с вердиктом match}
false_matches: {type: integer, description: Ложные match на негативных парах}
uncertain_rate: {type: number, description: Доля пар в зоне uncertain}
margin: {type: number, description: Нормированный зазор между классами (устойчивость)}
positive_pairs: {type: integer}
negative_pairs: {type: integer}
best: {$ref: '#/components/schemas/CalibrateCombo'}
ranking:
type: array
description: Все перебранные комбинации, от лучшей к худшей
items: {$ref: '#/components/schemas/CalibrateCombo'}
pairs:
type: array
description: Метрики всех пар при лучшей комбинации
items: {$ref: '#/components/schemas/CalibratePair'}
presets:
type: object
description: tp/fp стандартных профилей на тех же данных (facade/monument/repetitive)
additionalProperties: true
images:
type: array
items: {$ref: '#/components/schemas/CalibrateImage'}
skipped:
type: array
description: Файлы, отбракованные при загрузке (с причиной)
items: {$ref: '#/components/schemas/CalibrateSkipped'}
warnings:
type: array
items: {type: string}
selfcheck:
type: object
description: "Контроль: боевой compare_features воспроизвёл вердикты быстрого пути"
additionalProperties: true
processing_ms: {type: integer}
CalibrateCombo:
type: object
description: Комбинация pipeline-параметров с подобранными порогами вердикта
required: [geometry_model, lowe_ratio, ransac_reproj_threshold, thresholds, tp, fp, fn, f1, uncertain_rate, margin]
properties:
geometry_model: {type: string, enum: [homography, fundamental]}
lowe_ratio: {type: number}
ransac_reproj_threshold: {type: number}
thresholds:
type: object
description: Подобранные пороги вердикта
properties:
inliers_match: {type: integer}
inlier_ratio_match: {type: number}
coverage_min: {type: number}
inliers_uncertain_min: {type: integer}
tp: {type: integer}
fp: {type: integer}
fn: {type: integer}
f1: {type: number}
uncertain_rate: {type: number}
margin: {type: number}
CalibratePair:
type: object
required: [probe, ref, is_positive, good_matches, inliers, inlier_ratio, coverage, verdict]
properties:
probe: {type: string, description: Имя файла пробы}
ref: {type: string, description: Имя файла эталона}
is_positive: {type: boolean}
good_matches: {type: integer}
inliers: {type: integer}
inlier_ratio: {type: number}
coverage: {type: number}
verdict: {type: string, enum: [match, uncertain, no_match]}
CalibrateImage:
type: object
required: [name, group, keypoints]
properties:
name: {type: string}
group: {type: string, enum: [positive, negative]}
keypoints: {type: integer}
CalibrateSkipped:
type: object
required: [name, group, reason]
properties:
name: {type: string}
group: {type: string}
reason: {type: string}
ProfilesResponse:
type: object
required: [profiles]
@@ -502,6 +690,8 @@ components:
- FEATURE_BLOB_INVALID
- FEATURE_FORMAT_UNSUPPORTED
- TOO_MANY_REFERENCES
- TOO_MANY_CALIBRATION_IMAGES
- CALIBRATION_DATASET_INVALID
- UNKNOWN_PROFILE
- IMAGE_TOO_SMALL
- UNAUTHORIZED