AdarshDRC commited on
Commit
e4adc9f
·
verified ·
1 Parent(s): 5d013dc

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -11
main.py CHANGED
@@ -209,30 +209,26 @@ async def search_database(file: UploadFile = File(...), detect_faces: bool = For
209
  is_face = vec_dict["type"] == "face"
210
 
211
  # ── Score filtering ──────────────────────────────────────
212
- # Face lane: RetinaFace+GhostFaceNet 512-D cosine similarity.
213
- # Raw scores cluster around 0.3-0.5 for same person; anything
214
- # below 0.30 is noise. We remap to 75-99% for the UI.
215
  if is_face:
216
- RAW_THRESHOLD = 0.30
217
  if score < RAW_THRESHOLD:
218
  continue
219
  ui_score = 0.75 + ((score - RAW_THRESHOLD) / (1.0 - RAW_THRESHOLD)) * 0.24
220
  ui_score = min(0.99, ui_score)
221
  else:
222
  # Object lane: SigLIP+DINOv2 1536-D fused cosine similarity.
223
- # These vectors are dense and high-dimensional — even completely
224
- # different images can score 0.70-0.80 just by chance.
225
- # 0.82+ = genuinely similar images (same animal, same scene type)
226
- # 0.70-0.82 = loosely related (outdoor vs outdoor, animal vs animal)
227
- # < 0.70 = unrelated — hard filter these out entirely
228
- MIN_OBJECT_SCORE = 0.70
229
  if score < MIN_OBJECT_SCORE:
230
  continue
231
  ui_score = score
232
 
233
  caption = "👤 Verified Identity" if is_face else match["metadata"].get("folder", "🎯 Object Match")
234
  out.append({
235
- "url": match["metadata"].get("url", ""),
236
  "score": round(ui_score, 4),
237
  "caption": caption,
238
  })
 
209
  is_face = vec_dict["type"] == "face"
210
 
211
  # ── Score filtering ──────────────────────────────────────
212
+ # Face lane: GhostFaceNet 512-D cosine similarity.
213
+ # Raw scores 0.3-0.5 = same person. Remap to 75-99% for UI.
 
214
  if is_face:
215
+ RAW_THRESHOLD = 0.35 # matches original cloud_db.py
216
  if score < RAW_THRESHOLD:
217
  continue
218
  ui_score = 0.75 + ((score - RAW_THRESHOLD) / (1.0 - RAW_THRESHOLD)) * 0.24
219
  ui_score = min(0.99, ui_score)
220
  else:
221
  # Object lane: SigLIP+DINOv2 1536-D fused cosine similarity.
222
+ # Matches original cloud_db.py min_score=0.45 floor.
223
+ # Scores below 0.45 are pure noise — unrelated images.
224
+ MIN_OBJECT_SCORE = 0.45
 
 
 
225
  if score < MIN_OBJECT_SCORE:
226
  continue
227
  ui_score = score
228
 
229
  caption = "👤 Verified Identity" if is_face else match["metadata"].get("folder", "🎯 Object Match")
230
  out.append({
231
+ "url": match["metadata"].get("url") or match["metadata"].get("image_url", ""), # "image_url" = legacy key from cloud_db.py
232
  "score": round(ui_score, 4),
233
  "caption": caption,
234
  })