vitis::ai::FaceFeature - 1.2 English

Vitis AI Library User Guide (UG1354)

Document ID
UG1354
Release Date
2020-07-21
Version
1.2 English
Base class for getting the features of a face image (cv::Mat).

Input is a face image (cv::Mat).

Output is the features of a face in the input image.

Float sample code :

Note: Two interfaces are provided to get the float features or fixed features. features is a vector has 512 elements.
cv:Mat image = cv::imread("test_face.jpg");
auto network  = vitis::ai::FaceFeature::create("facerec_resnet20", true);
auto result = network->run(image);

Fixed sample code :

cv:Mat image = cv::imread("test_face.jpg");
auto network  = vitis::ai::FaceFeature::create("facerec_resnet20", true);
auto result = network->run_fixed(image);

Similarity calculation formula :

Fixed compare code :

 float feature_norm(const int8_t *feature) {
    int sum = 0;
    for (int i = 0; i < 512; ++i) {
        sum += feature[i] * feature[i];
    }
    return 1.f / sqrt(sum);
 }

/// This function is used for computing dot product of two vector
static float feature_dot(const int8_t *f1, const int8_t *f2) {
   int dot = 0;
   for (int i = 0; i < 512; ++i) {
      dot += f1[i] * f2[i];
   }
   return (float)dot;
}

float feature_compare(const int8_t *feature, const int8_t *feature_lib) {
   float norm = feature_norm(feature);
   float feature_norm_lib = feature_norm(feature_lib);
   return feature_dot(feature, feature_lib) * norm * feature_norm_lib;
}

/// This function is used for model "facerec_resnet20" 
float score_map_l20(float score) { return 1.0 / (1 + exp(-12.4 * score + 3.763)); }

/// This function is used for type "facerec_resnet64"
float score_map_l64(float score) { return 1.0 / (1 + exp(-17.0836 * score + 5.5707)); }

Display of the compare result with a set of images:

Figure 1. facecompare result image
Image sample_facecompare_result

Quick Function Reference

The following table lists all the functions defined in the vitis::ai::FaceFeature class:

Table 1. Quick Function Reference
Type Name Arguments
std::unique_ptr< FaceFeature > create
  • const std::string & model_name
  • bool need_preprocess
  FaceFeature
  • void
  FaceFeature
  • void
FaceFeature & operator=
  • void
  ~FaceFeature
  • void
int getInputWidth
  • void
int getInputHeight
  • void
size_t get_input_batch
  • void
FaceFeatureFloatResult run
  • const cv::Mat & img
FaceFeatureFixedResult run_fixed
  • const cv::Mat & img
std::vector< FaceFeatureFloatResult > run
  • images
std::vector< FaceFeatureFixedResult > run_fixed
  • images