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, )
| 14 | // backend picks the highest-confidence face and returns its |
| 15 | // L2-normalized embedding. |
| 16 | func 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 | } |
no test coverage detected