ValueError: pic should not have > 4 channels. Got XXX channels.

to_pil_image的channel设置在不同版本发生了重大改变, 是出现此错误的一个可能原因

这是一个torchvision.transforms.functional之下的function。在torchvision的0.16版本和0.17版本之间,其发生了重大改变。

python 复制代码
#0.16 版本
if pic.shape[-3] > 4:
        raise ValueError(f"pic should not have > 4 channels. Got {pic.shape[-1]} channels.")
#0.17版本
if pic.shape[-1] > 4:
        raise ValueError(f"pic should not have > 4 channels. Got {pic.shape[-1]} channels.")

例如segment_anything包中的ResizeLongestSide.apply_image就使用了这个函数,但是其安装要求没有强制要求torchvision>=0.17.

相关推荐
2601_9679873729 分钟前
Python 教程:默认字典(defaultdict)全维度深度指南
python·性能优化·数据处理·collections·defaultdict
鱼听禅1 小时前
Ubuntu安装YOLOv8进行菌落识别训练
linux·python·yolo·ubuntu
ZhengEnCi1 小时前
Agent 查不出代码 Bug 怎么办:一份带时间戳的调试日志与读日志排查流程
python·ai编程
威哥爱编程2 小时前
模拟面试智能体开发实战 05:给面试官接上题库和检索,题目结构化、大纲可溯源,AI 不再凭印象出题
python·agent·harmonyos
威哥爱编程2 小时前
模拟面试智能体开发实战 06:答得好怎么追问、答得错怎么点破,追问引擎让面试官会深挖会纠错
python·agent·harmonyos
codists3 小时前
《crafting interpreters》阅读笔记:4.6.2
python
2601_967979123 小时前
机器学习必修课:经典算法与Python实战
python·算法·机器学习·实战·课程
cpolar技术支持3 小时前
listen(5) 只排得住 5 个连接:第 6 个客户端卡在 connect 超时,进程活着端口却显示假活不放行
python·socket·tcp·cpolar·故障排查
梯度下降者4 小时前
我校学子斩获 2025 全国高新技术竞赛 Python 赛道全国一等奖
python·教育·竞赛·信息技术·人才培养
小小张说故事4 小时前
Python 的 memoryview 为什么能零拷贝:拆开 buffer protocol、cast 和那道 BufferError
python