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.

相关推荐
极序时代GEO品牌优化23 分钟前
杭州极序时代|面向地域、设备与用户画像的动态GEO
人工智能·python·算法·极序时代geo
qq_22589174661 小时前
基于Python的外卖订单数据分析可视化系统
python·信息可视化·django
MC皮蛋侠客1 小时前
SQLAlchemy 系列(三):声明式映射与 Schema——让类型、默认值和约束一致
数据库·python
会博通·代码搬运工1 小时前
会博通API对接实战:工程企业文档分布式采集系统的技术实现与Python SDK详解
开发语言·分布式·python·线性代数·矩阵·架构·电子档案合规
空堂与归1 小时前
大模型再火,也得先过 class 这一关
python
Muselit1 小时前
Python 泛型:把 list[User] 讲明白
python·fastapi
2501_916007471 小时前
Python实现HTTPS爬虫的完整指南:使用requests、BeautifulSoup、Selenium和Scrapy
爬虫·python·ios·小程序·https·uni-app·iphone
gptAI_plus2 小时前
别把整个仓库塞给 AI:用 Python 生成安全的代码上下文清单
python·chatgpt
吃饱了得干活2 小时前
Agent 记忆系统:从短期记忆到长期记忆
python·langchain·agent
大鱼>2 小时前
DSPy:LLM程序自动编译与提示词优化
开发语言·人工智能·python·深度学习