python代码运行报错

UserWarning: Argument interpolation should be of type InterpolationMode instead of int. 
Please, use InterpolationMode enum. "Argument interpolation should be of type InterpolationMode instead of int. "

这种是由于 包之间不兼容问题导致。根据报错可以发现,提示使用”use InterpolationMode enum”

修改方法

导入 InterpolationMode模块

from torchvision.transforms import InterpolationMode
一、将Image替换为InterpolationMode

pycharm中ctrl+f搜索Image,找到 Image.BICUBIC字样,替换为 InterpolationMode.BICUBIC
即:
报错代码:

transforms_ = transforms.Compose([
    transforms.Resize((opt.img_height, opt.img_width), Image.BICUBIC),
    transforms.ToTensor(),
])

修改后代码:

transforms_ = transforms.Compose([
    transforms.Resize((opt.img_height, opt.img_width), InterpolationMode.BICUBIC),
    transforms.ToTensor(),
])
二、将Image的实参改为InterpolationMode

报错代码:

transforms.Resize(size=(opt.h, opt.w),interpolation=3) ;此处3为Image.BICUBIC的实参

修改后代码:

transforms.Resize(size=(opt.h, opt.w),interpolation=3) 
Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐