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.

相关推荐
梦幻精灵_cq6 分钟前
《双征color》诗解——梦幻精灵_cq对终端渲染的数据结构设计模型式拓展
数据结构·python
喵手24 分钟前
Python爬虫零基础入门【第八章:项目实战演练·第3节】上线与运维入门:定时运行、日志轮转、失败告警(轻量版)!
爬虫·python·爬虫实战·python爬虫工程化实战·零基础python爬虫教学·定时运行·日志轮转
weixin_6600967836 分钟前
flash-attention总是安装失败
python·flash-attention
yaoxin52112338 分钟前
303. Java Stream API - 查找元素
java·windows·python
子午1 小时前
【2026计算机毕设】蔬菜识别系统~Python+深度学习+人工智能+算法模型+TensorFlow
人工智能·python·深度学习
kong79069281 小时前
Python 调用大模型(LLM)
人工智能·python·大模型llm
深蓝电商API1 小时前
Selenium 爬取 Canvas 渲染的数据图表
爬虫·python·selenium
Just right1 小时前
python安装包问题
开发语言·python
hhy_smile1 小时前
Function in Python
python
dxz_tust1 小时前
flow match简单直观理解
开发语言·python·深度学习·扩散模型·流匹配·flow match