python - 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 构造函数,但我得到了类似的错误。
解决方案
我尝试删除它unsqueeze
并且它起作用
了我所遵循的指南是使用opencv以外的东西来加载图像,这可能会将图像作为图像数组/张量返回
推荐阅读
- python - flask_rq, redis, rq 将作业移动到 FailedJobRegistry 主力进程意外终止(waitpid 返回无)
- api - Identity Server 4 Postman 请求令牌不起作用
- algorithm - 如何在 MQL4 / MT4 中对很多指数进行分组?
- php - 如何显示显示当前值的数据库动态生成的选项列表
- c - 如何在 C 中使用 fgets 解决此问题?
- c# - NHibernate.MappingException 不存在该类的映射
- javascript - 在 React Native 中使用 '.splice()' 添加到数组
- mysql - MYSQL 5:如果语句为假,则返回表达式,类似于 NULLIF
- java - 我什么时候可以看到休眠实体的更新?
- mysql - 通过 Heroku 到 AWS 对等连接的 RDS MySQL 连接超时