Photo: Xiuren
def __init__(self, root_dir: str, transform=None): self.root = pathlib.Path(root_dir) if not self.root.is_dir(): raise ValueError(f"❌ root_dir is not a valid directory.") self.paths = [ p for p in self.root.rglob("*") if p.suffix.lower() in self.SUPPORTED_EXTS ] if not self.paths: raise RuntimeError(f"❌ No images found in root_dir!") self.transform = transform
# Example 1️⃣ – Nearest‑Neighbor search (cosine similarity ≈ inner product after L2‑norm) index = faiss.IndexFlatIP(X.shape[1]) # inner product faiss.normalize_L2(X) # ensure unit length if you didn't L2‑norm earlier index.add(X) # populate xiuren photo
""" extract_features.py