Faces: Migrate & normalize face.Children from Embeddings to Clusters

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2025-10-05 18:11:18 +02:00
parent 4b625d8217
commit 00d41144a0
5 changed files with 64 additions and 38 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -71,9 +71,13 @@ func RandomEmbedding() (result Embedding) {
func RandomKidsEmbedding() (result Embedding) {
result = make(Embedding, 512)
if len(Children) == 0 {
return result
}
d := 0.1 / 512.0
n := 1 + rand.IntN(len(Children)-1)
e := Children[n]
n := rand.IntN(len(Children))
e := Children[n].Embedding
for i := range result {
result[i] = RandomFloat64(e[i], d)

View file

@ -54,7 +54,11 @@ func TestEmbeddings_Kind(t *testing.T) {
assert.Equal(t, RegularFace, regular.Kind())
})
t.Run("IsChild", func(t *testing.T) {
assert.Equal(t, KidsFace, Children.Kind())
clustersEmbeddings := make(Embeddings, len(Children))
for i := range Children {
clustersEmbeddings[i] = Children[i].Embedding
}
assert.Equal(t, KidsFace, clustersEmbeddings.Kind())
})
t.Run("IgnoredFace", func(t *testing.T) {
assert.Equal(t, IgnoredFace, ignored.Kind())

View file

@ -88,7 +88,12 @@ func TestFace_ResolveCollision(t *testing.T) {
assert.Less(t, m.CollisionRadius, 1.272)
})
t.Run("SubjectIdEmpty", func(t *testing.T) {
m := NewFace("", SrcAuto, face.Children)
childrenEmbeddings := make(face.Embeddings, len(face.Children))
for i := range face.Children {
childrenEmbeddings[i] = face.Children[i].Embedding
}
m := NewFace("", SrcAuto, childrenEmbeddings)
if reported, err := m.ResolveCollision(MarkerFixtures.Pointer("1000003-4").Embeddings()); err != nil {
t.Fatal(err)
} else {