微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

训练 facenet 时出现 ValueError

如何解决训练 facenet 时出现 ValueError

我正在尝试此代码 https://github.com/arsfutura/face-recognition ,但是在运行 sh tasks/train.sh images/ 时,我收到 valueerror 为 :-

images/rah/ra.jpg
/home/pi/.local/lib/python3.7/site-packages/facenet_pytorch/models/utils/detect_face.py:146: UserWarning: This overload of nonzero is deprecated:
nonzero()
Consider using one of the following signatures instead:
nonzero(*,bool as_tuple) (Triggered internally at ../torch/csrc/utils/python_arg_parser.cpp:882.)
bb = mask.nonzero().float().flip(1)
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py",line 193,in _run_module_as_main
"main",mod_spec)
File "/usr/lib/python3.7/runpy.py",line 85,in _run_code
exec(code,run_globals)
File "/home/pi/face-recognition/training/train.py",line 99,in
main()
File "/home/pi/face-recognition/training/train.py",line 84,in main
embeddings,labels,class_to_idx = load_data(args,features_extractor)
File "/home/pi/face-recognition/training/train.py",line 61,in load_data
embeddings,labels = dataset_to_embeddings(dataset,line 41,in dataset_to_embeddings
_,embedding = features_extractor(transform(Image.open(img_path).convert('RGB')))
File "/home/pi/face-recognition/face_recognition/face_features_extractor.py",line 26,in call
return self.extract_features(img)
File "/home/pi/face-recognition/face_recognition/face_features_extractor.py",line 15,in extract_features
bbs,_ = self.aligner.detect(img)
File "/home/pi/.local/lib/python3.7/site-packages/facenet_pytorch/models/mtcnn.py",line 308,in detect
self.device
File "/home/pi/.local/lib/python3.7/site-packages/facenet_pytorch/models/utils/detect_face.py",line 66,in detect_face
tmp[(dy[k] - 1):edy[k],(dx[k] - 1):edx[k],:] = img[(y[k] - 1):ey[k],(x[k] - 1):ex[k],:]
ValueError: Could not broadcast input array from shape (0,1364,3) into shape (0,3)

我什至尝试在 detect_face.py 的第 65 行硬编码 tmp = np.zeros((0,3)) 只是为了测试,但没有运气。

解决方法

你为什么不在 deepface 中使用 facenet?您只需将精确的图像路径成对传递,它就会构建一个人脸识别管道。我的意思是验证功能在后台处理人脸检测和对齐。

#!pip install deepface
from deepface import DeepFace
obj = DeepFace.verify("img1.jpg","img2.jpg",model_name = 'Facenet')
print(obj["verified"])

或者您可以类似地在数据库中查找身份。在这里,您需要将扩展​​名为 .jpg 或 .png 的面部图像存储在一个文件夹中,并将其传递给数据库路径。

df = DeepFace.find("img1.jpg",db_path="C:/my_db",model_name = 'Facenet')
print(df.head())

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。