#1637·deepface

[FEATURE]: Define scalar custom distance behavior for batched find

Author: Afloat16Created Sep 30, 2026Updated Sep 30, 2026
Labelsenhancement

Description

Following #1620, the documented custom metric accepts two embeddings and returns a distance, but the batched path passes two entire matrices to it. SciPy scalar metrics therefore fail:

python
import numpy as np
from scipy.spatial.distance import euclidean
from deepface.modules.verification import find_distance
find_distance(np.array([[1., 0.], [0., 1.]]), np.array([[1., 0.]]), euclidean)
# ValueError: Input vector should be 1-D.

Would you accept defining custom callbacks as scalar, applied to each pair of 1D embeddings for batches, returning a matrix of shape (number of targets, number of gallery entries)? Built-in metrics would retain their vectorized path.

This would make ordinary and batched find consistent for SciPy cosine/cityblock/euclidean, but callbacks specifically written to accept whole matrices would need adaptation. I do not want to silently introduce that compatibility change without agreement. An alternative is an explicit separate batch callback API.

Additional Info

Checked current master e1b38a8 and searched existing issues/PRs. The candidate has 21 focused distance tests passing with normal project imports (14 fail on unchanged master), covering pair ordering, asymmetric callbacks, empty batches and unrounded scalar outputs. Native find integration is being checked separately. This proposes a contract decision, not a performance optimization; no automatic exception-based scalar/matrix fallback is proposed. I will hold the implementation PR until the intended contract is confirmed.