View Source Evision.Zoo.FaceRecognition.SFace (Evision v0.1.28)

SFace: Sigmoid-Constrained Hypersphere Loss for Robust Face Recognition

Link to this section Summary

Functions

Default configuration.

Docs in smart cell.

Get feature for the input face image.

Initialize model.

Model URL and filename of predefined model.

Preprocessing the input face image.

Customizable parameters from smart cell.

Smart cell tasks.

Generate quoted code from smart cell attrs.

Link to this section Functions

@spec default_config() :: map()

Default configuration.

@spec docs() :: String.t()

Docs in smart cell.

Link to this function

infer(self, face_image, bbox \\ nil)

View Source

Get feature for the input face image.

Positional arguments
  • self: Evision.FaceRecognizerSF.t().

    An initialized FaceRecognizerSF model.

  • face_image: Evision.Mat.maybe_mat_in().

    Input face image.

  • bbox: Evision.Mat.maybe_mat_in().

    Optional bounding box that specifies the face location in the given image.

    Defaults to nil.

    When bbox is not nil, preprocess/3 will crop the face from given image and use the cropped image as the input.

    Otherwise, face_image will be set as the input.

Link to this function

init(model_path, opts \\ [])

View Source
@spec init(binary() | :default_model | :quant_model, nil | Keyword.t()) ::
  {:error, String.t()} | Evision.FaceRecognizerSF.t()

Initialize model.

Positional arguments
  • model: String.t() | :default_model | :quant_model.

    • When model is a string, it will be treat as the path to a weight file and init/2 will load the model from it.

    • When model is either :default_model or :quant_model, init/2 will download and load the predefined model.

Keyword arguments
  • cache_dir: String.t().

    Path to the cache directory.

    Optional. Defaults to :filename.basedir(:user_cache, "", ...)

  • backend: integer().

    Specify the backend.

    Optional. Defaults to Evision.Constant.cv_DNN_BACKEND_OPENCV().

  • target: integer().

    Specify the target.

    Optional. Defaults to Evision.Constant.cv_DNN_TARGET_CPU().

Link to this function

match(self, original, comparison, opts \\ [])

View Source

Compare two faces.

Positional Arguments
  • self: Evision.FaceRecognizerSF.t()

  • original: Evision.Mat.maybe_mat_in().

    Original face.

  • comparison: Evision.Mat.maybe_mat_in().

    Comparison face.

Keyword Arguments
  • distance_type: atom.

    Either :cosine_similarity or :l2_norm. Defaults to :cosine_similarity.

  • cosine_threshold: number().

    Defaults to 0.363.

  • l2_norm_threshold: number().

    Defaults to 1.128.

  • detector_module: module().

    Face detector module. Defaults to Evision.Zoo.FaceDetection.YuNet.

  • detector_model: String.t() | atom().

    Face detector model name or path to model weights. Defaults to :default_model.

  • detector_opts: Keyword.t().

    Face detector initialization options. Defaults to [].

Return

A map with three keys.

  • matched: boolean()

    true if two faces match, false otherwise.

  • measure: "cosine_score" | "l2_norm_distance"

    Distance type.

  • retval: number()

    • When measure == "cosine_score", retval is the cosine similarity score.
    • When measure == "l2_norm_distance", retval is the L2 norm distance.
Link to this function

match_feature(self, face1_feat, face2_feat, opts \\ [])

View Source

Compare two face features.

Positional Arguments
  • self: Evision.FaceRecognizerSF.t()

  • face1_feat: Evision.Mat.maybe_mat_in().

    Feature value of face 1.

  • face2_feat: Evision.Mat.maybe_mat_in().

    Feature value of face 2.

Keyword Arguments
  • distance_type: atom.

    Either :cosine_similarity or :l2_norm. Defaults to :cosine_similarity.

  • cosine_threshold: number().

    Defaults to 0.363.

  • l2_norm_threshold: number().

    Defaults to 1.128.

Return

A map with three keys.

  • matched: boolean()

    true if two faces match, false otherwise.

  • measure: "cosine_score" | "l2_norm_distance"

    Distance type.

  • retval: number()

    • When measure == "cosine_score", retval is the cosine similarity score.
    • When measure == "l2_norm_distance", retval is the L2 norm distance.
@spec model_info(:default_model | :quant_model) :: {String.t(), String.t()}

Model URL and filename of predefined model.

Link to this function

preprocess(self, face_image, bbox)

View Source

Preprocessing the input face image.

infer/3 will call this function automatically.

Positional arguments
  • self: Evision.FaceRecognizerSF.t().

    An initialized FaceRecognizerSF model.

  • face_image: Evision.Mat.maybe_mat_in().

    Input face image.

  • bbox: Evision.Mat.maybe_mat_in().

    Optional bounding box that specifies the face location in the given image.

    Defaults to nil.

    When bbox is not nil, preprocess/3 will crop the face from given image and return the cropped image.

    Otherwise, face_image will be returned.

@spec smartcell_params() :: Evision.Zoo.smartcell_params()

Customizable parameters from smart cell.

@spec smartcell_tasks() :: Evision.Zoo.smartcell_tasks()

Smart cell tasks.

A list of variants of the current model.

@spec to_quoted(map()) :: list()

Generate quoted code from smart cell attrs.