MCPcopy
hub / github.com/mudler/LocalAI / FaceEmbed

Function FaceEmbed

core/backend/face_embed.go:16–44  ·  view source on GitHub ↗

FaceEmbed loads the face recognition backend and returns a 512-d face embedding for the base64-encoded image. Unlike ModelEmbedding it passes the image through PredictOptions.Images — the insightface backend picks the highest-confidence face and returns its L2-normalized embedding.

(
	ctx context.Context,
	imgBase64 string,
	loader *model.ModelLoader,
	appConfig *config.ApplicationConfig,
	modelConfig config.ModelConfig,
)

Source from the content-addressed store, hash-verified

14// backend picks the highest-confidence face and returns its
15// L2-normalized embedding.
16func FaceEmbed(
17 ctx context.Context,
18 imgBase64 string,
19 loader *model.ModelLoader,
20 appConfig *config.ApplicationConfig,
21 modelConfig config.ModelConfig,
22) ([]float32, error) {
23 opts := ModelOptions(modelConfig, appConfig)
24 faceModel, err := loader.Load(opts...)
25 if err != nil {
26 recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil)
27 return nil, err
28 }
29 if faceModel == nil {
30 return nil, fmt.Errorf("could not load face recognition model")
31 }
32
33 predictOpts := gRPCPredictOpts(modelConfig, loader.ModelPath)
34 predictOpts.Images = []string{imgBase64}
35
36 res, err := faceModel.Embeddings(ctx, predictOpts)
37 if err != nil {
38 return nil, err
39 }
40 if len(res.Embeddings) == 0 {
41 return nil, fmt.Errorf("face embedding returned empty vector (no face detected?)")
42 }
43 return res.Embeddings, nil
44}

Callers 3

FaceEmbedEndpointFunction · 0.92
FaceRegisterEndpointFunction · 0.92
FaceIdentifyEndpointFunction · 0.92

Calls 5

ModelOptionsFunction · 0.85
recordModelLoadFailureFunction · 0.85
gRPCPredictOptsFunction · 0.85
LoadMethod · 0.65
EmbeddingsMethod · 0.65

Tested by

no test coverage detected