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.

相关推荐
fenglllle1 分钟前
chromadb emmbedding 向量检索
人工智能·python·embedding
cui_ruicheng5 分钟前
Python从入门到实战(六):非序列容器
开发语言·python
飞猪~35 分钟前
Langchain python版本 LLM 重要函数invoke,ainvoke,stream,astream,batch,abatch
python·langchain·batch
沙蒿同学1 小时前
当古诗词遇上 AI:从 38 万句诗词中取一个好名字
python·算法·架构
xxie1237942 小时前
Python装饰器与语法糖
开发语言·python
CClaris2 小时前
大模型量化从0到1(五):GPTQ 原理详解 + 从零量化一个真实大模型
人工智能·python·算法·机器学习
Railshiqian2 小时前
UserPickerActivity 内部逻辑分析
开发语言·python
一tiao咸鱼2 小时前
前端转 agent # 02 - FastAPI 框架入门与原理
前端·python
Yolo566Q2 小时前
Noah-MP陆面过程模型建模方法与站点、区域模拟实践技术应用
开发语言·python
肖永威3 小时前
麒麟 V10 编译 Python 3.11 依赖包缺失与版本冲突问题解决实录
运维·python·麒麟操作系统