python - dlib python人脸编码vs c++人脸编码
问题描述
我正在尝试在 C++ 中生成与此 python 包装库提供的相同的面部编码: https ://github.com/ageitgey/face_recognition/blob/master/face_recognition/api.py
C++ 代码:
frontal_face_detector detector;
...
for (auto face : detector(img, numberOfTimesToUpsample))
{
auto shape = sp(img, face); //sp = shape_predictor 5 face landmarks same as python lib
matrix<rgb_pixel> face_chip;
extract_image_chip(img, get_face_chip_details(shape,150,0.25), face_chip); // Chip size and padding same as dlib python settings
faces.push_back(move(face_chip));
coords.push_back(face);
}
...
std::vector<dlib::matrix<float,0,1>> face_descriptors = net(faces, 16); // net is dlib_face_recognition_resnet_model_v1 same as python lib
...
python库默认上采样一次,并使用小(5点)形状预测器,
所以我用numberOfTimesToUpsample
as 1 调用 c++ 代码,因为我的 c++ 代码不做抖动,所以我调用 python 代码为:
encoding = face_recognition.face_encodings(image, num_jitters=0)[0]
然而,当我通过两个系统运行一张带有人脸的图像时,编码结果却大不相同。例如,前几个 dims 的 c++ 输出:
-0.131519
0.0520326
0.0556113
-0.101895
-0.165266
和蟒蛇:
-0.14469159
0.04349349
0.03403644
-0.1062524
-0.18296713
我在这里检查了用于计算编码的 dlib C++-Python API:https ://github.com/davisking/dlib/blob/master/tools/python/src/face_recognition.cpp并且除了没有之外真的看不到任何主要差异铸造一切double
。
编辑:我也尝试过转换为双精度。所有的数字都是一样的。
我尝试构建链接到 python dlib 库附带的 .so 文件的项目。仍然得到相同的数字。
我检查了我读取图像数据的方法是否产生与 python PIL.Image 读取到 numpy-array 相同的 RGB 像素值。那里的一切看起来都很好。
我希望能够可靠地产生相同的输出。我错过了什么?
解决方案
推荐阅读
- c# - 在 Windows 服务的 OnStop 中调用字段的 Dispose 方法
- java - 旧版 SOAP Web 服务 - 需要一个新客户端
- json - 在 Elasticsearch 上从 metricbeat 中聚合“主机”JSON 对象
- bash - Hostapd 忽略通道配置
- ios - 释放后如何将 WKWebView 内存 (RAM) 中的用户数据清零
- linux - 删除特定单词出现的最后一行的字符
- go - 为什么正常返回可以隐藏命名返回正确提供给调用者的恐慌?
- java - java XMLGregorianCalendar 显示不同年份的转换
- r - 对多个变量执行相同的操作,分配结果
- awk - 仅打印匹配字符串之间的特定列