我正在尝试建立一个使用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构造函数,但我得到了类似的错误。
发布于 2021-09-03 14:02:48
我试着移除unsqueeze,它起了作用
我所遵循的指南是使用opencv以外的其他东西来加载图像,它可能将图像返回为图像的数组/张量。
https://stackoverflow.com/questions/68882782
复制相似问题