【问题标题】:PyTorch resnet bad tensor dimensionsPyTorch resnet 坏张量维度
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    • 2020-09-26
    • 2021-02-10
    • 2021-04-05
    • 2020-08-26
    • 2020-01-02
    相关资源
    最近更新 更多