首页 > 解决方案 > PyTorch resnet 坏张量维度

问题描述

我正在尝试使用 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 构造函数,但我得到了类似的错误。

标签: pythonpytorchface-recognitionface-detectionresnet

解决方案


我尝试删除它unsqueeze并且它起作用
了我所遵循的指南是使用opencv以外的东西来加载图像,这可能会将图像作为图像数组/张量返回


推荐阅读