Interface

Model Serving Contract

모델 개발 담당과 앱 개발 담당 사이의 인터페이스다. 최신 Sprint 2 기준은 MobileCLIP2-S3 multi-task checkpoint에서 export한 FP16 mixed ONNX bundle이다. 앱은 image encoder와 text encoder에서 각각 embedding을 얻고, prototype/text index와 cosine similarity를 계산해 Top-3와 confidence state를 산출한다.

현재 상태

현재 전달 기준mobileclip2_s3_server_full_ce_hardneg_fold3_20260611_214421/mobile_artifacts/fp16다. Sprint 1의 mobile_artifacts_int8/landmark_encoder.onnx 구조는 데모앱 legacy 기준으로만 남긴다. 최신 앱은 manifest.json을 읽어 image/text encoder 파일명을 확인해야 한다.

App main 확인 기준: lpcvc-2026-CNU/App@598da589 기준으로 image/text encoder split, Android asset cache 갱신, semantic text search, 23-class prototype, 26개 상세정보 catalog, parent/sub-landmark 표시 기준이 반영되어 있다. 다만 대용량 .onnx, .onnx.data 파일은 Git에 올리지 않으므로, main checkout 직후에는 공유 artifact 폴더에서 직접 배치해야 한다.

Sprint 2 Handoff Package

mobile_artifacts/fp16/
  mobileclip2_s3_server_full_ce_hardneg_image_encoder_fp16_mixed.onnx
  mobileclip2_s3_server_full_ce_hardneg_image_encoder_fp16_mixed.onnx.data
  mobileclip2_s3_server_full_ce_hardneg_text_encoder_fp16_mixed.onnx
  mobileclip2_s3_server_full_ce_hardneg_text_encoder_fp16_mixed.onnx.data
  preprocessing.json
  tokenizer.json
  tokenizer_bundle.json
  text_index.json
  text_search_policy.json
  text_query_regression_set.json
  text_search_eval_report.json
  confidence_policy.json
  prototype_index.json
  classes.json
  labels_master.json
  manifest.json
  config.yaml

.onnx.onnx.data는 한 쌍이다. 둘 중 하나라도 빠지면 모델을 로드할 수 없다. 이미지 검색은 image encoder와 prototype_index.json를 사용하고, 텍스트 검색은 tokenizer_bundle.json으로 만든 text_tokens를 text encoder에 넣어 512차원 text embedding을 얻은 뒤 text_index.json과 비교한다.

GitHub main에는 manifest.json, classes.json, prototype_index.json, text_index.json, tokenizer_bundle.json, policy/eval JSON처럼 작은 계약 파일만 추적한다. 실제 실행에 필요한 4개 대용량 파일 image_encoder.onnx, image_encoder.onnx.data, text_encoder.onnx, text_encoder.onnx.data는 공유 압축본 또는 로컬 artifact source에서 assets/mobile_artifacts_fp16/ 아래에 넣어야 한다.

App Main Verification

항목 main 기준 확인 내용
App revision origin/main@598da589, PR #11 모델 연동과 PR #12 Android asset cache 수정 반영.
Artifact metadata assets/mobile_artifacts_fp16/에 16개 metadata/search/tokenizer/policy 파일이 추적됨. 대용량 ONNX 4개는 Git 미추적.
Model contract manifest.json 기준 MobileCLIP2-S3, fp16, class_count=23, embedding_dim=512, opset=18, ir_version=9.
Image/Text sessions OnnxInferenceService가 image encoder와 text encoder session을 분리해 로드한다.
Android cache MainActivity.ktmanifest.json을 읽고 4개 ONNX/external data 파일을 앱 내부 저장소로 복사하며, stream 기반 크기 비교로 stale cache를 갱신한다.
Text search SemanticTextSearchService가 text encoder cosine score와 SQLite keyword score를 semantic_text_fusion으로 결합한다.
Catalog assets/landmark_info.json은 26개 표시 항목을 가지며, 23개 모델 class와 parent-only 항목을 함께 관리한다.
Parent mapping 경복궁, 창경궁, 덕수궁 세부 class 12개가 parent_landmark_id로 상위 장소와 연결된다.

파일 이름 규칙

파일명은 모델, encoder 종류, precision 정책을 드러내야 한다. 앱은 하드코딩된 파일명을 직접 쓰기보다 manifest.jsonimage_encoder, text_encoder 항목을 읽는 것을 기본으로 한다.

mobileclip2_s3_server_full_ce_hardneg_image_encoder_fp16_mixed.onnx
mobileclip2_s3_server_full_ce_hardneg_text_encoder_fp16_mixed.onnx

fp16_mixed는 일부 weight를 FP16으로 저장하되, 계산 안정성을 위해 필요한 곳은 FP32 cast를 유지한다는 뜻이다. 순수 FP16보다 보수적이지만, 현재 검증에서는 image/text embedding parity가 안정적이다.

앱이 읽어야 하는 파일의 역할

파일 역할
manifest.json image/text encoder ONNX 파일명, 입력 이름, 출력 이름, precision 정책을 확인한다.
preprocessing.json 이미지 resize/crop/normalize 기준이다. 입력은 image: [batch, 3, 224, 224] float32다.
tokenizer.json 텍스트 tokenizer의 원천 모델 정보를 기록한다. 앱의 실제 재현에는 tokenizer_bundle.json을 사용한다.
tokenizer_bundle.json Dart에서 OpenCLIP tokenizer를 재현하기 위한 vocab, BPE merge, special token, fixture token ids다.
prototype_index.json image embedding과 cosine similarity로 비교할 landmark prototype 목록이다.
text_index.json 자연어 query embedding과 비교할 catalog text embedding 목록이다.
text_search_policy.json semantic_score, keyword_score, margin, out-of-scope threshold를 관리한다.
text_query_regression_set.json, text_search_eval_report.json 텍스트 검색 전체 query 평가 세트와 결과 기록이다. PR 검증과 문서화의 근거로 사용한다.
landmark catalog / DB 사용자에게 보여줄 이름, 설명, 대표 이미지, 상세정보, parent_landmark_id를 제공한다.
text catalog / text index 자연어 검색 품질을 위한 alias, query examples, text embedding 비교 대상을 제공한다.

Role Boundary

주체 책임
모델 개발 담당 image/text encoder ONNX bundle, preprocessing/tokenizer spec, prototype/text index, confidence policy seed, regression report, training metrics 제공.
앱 개발 담당 사진/자연어 검색 UI, 상세정보 DB, 사용자 문구, 로그 저장, bundle 파일 배치.
연동 기준 landmark_id, Top-3 schema, status values, reason codes를 맞춘다.

Image Search Input Contract

{
  "kind": "image",
  "image_path": "local/path/to/user_image.jpg",
  "top_k": 3
}

Text Search Input Contract

{
  "kind": "text",
  "query": "돌담 있는 공원",
  "top_k": 3,
  "language_hint": "ko"
}

text search는 앱에서 query를 정규화하고 tokenizer로 text_tokens를 만든 뒤 text encoder를 실행한다. 직접 문자열/alias match와 embedding similarity fusion은 검색 서비스 레이어에서 함께 사용할 수 있다.

Output Contract

{
  "status": "ambiguous",
  "message_key": "ambiguous_candidates",
  "top_k": [
    {
      "rank": 1,
      "landmark_id": "gwanghwamun",
      "landmark_name_ko": "광화문",
      "raw_score": 0.40,
      "display_score": 40,
      "score_type": "cosine_similarity"
    }
  ],
  "confidence": {
    "top1_score": 0.40,
    "top2_score": 0.31,
    "margin": 0.09,
    "policy_version": "sprint2-s3-fp16-policy-v1",
    "reason_codes": ["top1_below_match", "margin_low"]
  },
  "runtime": {
    "backend": "onnx-fp16-mixed",
    "artifact_dir": "mobile_artifacts/fp16",
    "model_version": "mobileclip2_s3_server_full_ce_hardneg_fold3_20260611_214421",
    "elapsed_ms": 314
  }
}

Text Search Output Additions

자연어 검색은 이미지 검색과 같은 Top-3 UI를 쓰되 score 의미를 분리한다. raw_score는 text encoder cosine similarity이고, final_text_score는 semantic score와 SQLite keyword score를 결합한 값이다.

{
  "rank": 1,
  "landmark_id": "naksan_park",
  "parent_landmark_id": null,
  "score_type": "semantic_text_fusion",
  "raw_score": 0.43,
  "semantic_score": 0.43,
  "keyword_score": 0.60,
  "final_text_score": 0.47,
  "display_score": 47,
  "matched_text": "성곽길과 도시 전망이 보이는 공원",
  "text_type": "description"
}

현재 fusion 기본값은 0.75 * semantic_score + 0.25 * keyword_score다. keyword hit가 없고 score/margin이 낮은 query는 out_of_scope로 처리한다.

Status Values

status 의미 앱 동작
matched 지원 범위 내 랜드마크로 충분히 판단. Top-3와 상세정보 이동 제공.
ambiguous 후보는 있으나 한 곳으로 확정하기 어려움. “확정하기 어렵습니다” 문구와 함께 후보를 참고용으로 표시.
out_of_scope 지원 범위 밖 또는 confidence 부족. 기본 화면에서 확정 후보를 숨기고 안내 문구 표시. 후보는 로그에 남김.
low_quality 흐림, 어두움, 작은 crop 등 품질 문제. 재촬영 또는 더 선명한 사진 요청.

NPU 측정 caveat

Qualcomm AI Hub artifact는 Snapdragon 실기기 최적화 후보로 별도 비교한다. 현재 handoff 기준은 FP16 mixed ONNX bundle이며, Qualcomm INT8/QNN은 정확도와 latency를 다시 검증한 뒤 교체 후보로 둔다.

Versioning Rule

앱은 artifact 폴더명만 보고 동작하면 안 된다. manifest.jsonmodel_name, embedding_dim, image_encoder, text_encoder, class_count, precision_policy를 확인해야 한다. 모델이 바뀌면 prototype/text index도 같은 version으로 다시 생성해야 한다.