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.

相关推荐
数据智能老司机21 小时前
精通 Python 设计模式——分布式系统模式
python·设计模式·架构
数据智能老司机1 天前
精通 Python 设计模式——并发与异步模式
python·设计模式·编程语言
数据智能老司机1 天前
精通 Python 设计模式——测试模式
python·设计模式·架构
数据智能老司机1 天前
精通 Python 设计模式——性能模式
python·设计模式·架构
c8i1 天前
drf初步梳理
python·django
每日AI新事件1 天前
python的异步函数
python
这里有鱼汤1 天前
miniQMT下载历史行情数据太慢怎么办?一招提速10倍!
前端·python
databook1 天前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室1 天前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三1 天前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试