RuntimeError: stack expects each tensor to be equal size, but got [1180, 1070, 3] at entry 0 and [77

在这里插入图片描述意思是加载的一批图片里面存在大小不一致的情况,分别是[1100,1070]和[776,710]

然后根据这个问题,仔细看了下图片大小,确实存在不一样的尺寸
在这里插入图片描述
在这里插入图片描述
将图片一致化的方法:

from PIL import Image
import os.path
import glob
 
 
def Resize(file, outdir, width, height):
    imgFile = Image.open(file)
    try:
        newImage = imgFile.resize((width, height), Image.BILINEAR)
        newImage.save(os.path.join(outdir, os.path.basename(file)))
    except Exception as e:
        print(e)
 
 
for file in glob.glob("C:\\Users\\user\\PycharmProjects\\attention1\\result\\2\\*.png"):  # 图片所在的目录
    Resize(file, "C:\\Users\\user\\PycharmProjects\\attention1\\result1\\2", 145, 121)  # 新图片存放的目录,需要统一的尺寸

参考于https://blog.csdn.net/qq_40929682/article/details/121523645?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165044233716780264076427%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=165044233716780264076427&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-1-121523645.142v9control,157v4control&utm_term=RuntimeError%3A+stack+expects+each+tensor+to+be+equal+size%2C+but+got+%5B471%2C+525%2C+4%5D+at+entry+0+and+%5B471%2C+525%2C+3%5D+at+entry+4&spm=1018.2226.3001.4187

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值