【问题标题】:Getting ValueError while training facenet训练facenet时出现ValueError
【发布时间】:2021-04-01 07:33:00
【问题描述】:

我正在尝试此代码 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, features_extractor)
File "/home/pi/face-recognition/training/train.py", 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,0,3)

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

【问题讨论】:

标签: python image opencv machine-learning facenet


【解决方案1】:

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

#!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())

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 2021-08-27
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-22
    • 2018-07-25
    相关资源
    最近更新 更多