【发布时间】:2021-10-23 05:23:16
【问题描述】:
我正在尝试使用 Pytorch 设置人脸检测/识别管道。
我使用 opencv 加载图像
image = cv2.imread('...')
我加载了mtcnn 人脸检测和resnet 人脸识别模型
self.mtcnn = MTCNN(keep_all=True, device=self.device)
self.resnet = InceptionResnetV1(pretrained='vggface2').eval()
然后我运行检测和识别
cropped = detector.mtcnn(image)
detector.resnet(cropped.unsqueeze(0))
得到这个错误
Expected 4-dimensional input for 4-dimensional weight [32, 3, 3, 3], but got 5-dimensional input of size [1, 1, 3, 160, 160] instead
我还尝试将图像大小调整为 512x512 并将 image_size=512 传递给 MTCNN 构造函数,但我得到了类似的错误。
【问题讨论】:
-
请提供完整的错误跟踪。
-
你试过不解压吗?提供给detector.mtcnn 的图像可能已经未压缩。您提供 5d 张量而不是 4d [B, H, W, F] 张量是有道理的。
标签: python pytorch face-recognition face-detection resnet