图像插值算法

本文介绍在使用PyTorch进行图像变换时,如何处理警告'interpolation should be of type InterpolationMode',并详细讲解了最近邻、双线性和Lanczos插值等。未来版本将弃用数字参数,建议采用官方提供的InterpolationMode枚举值进行转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图像插值算法

最近使用pytorch对图像进行变换遇到一个
warning:"Argument interpolation should be of type InterpolationMode instead of int. "
也就是这个函数

transforms.Resize(self.height, self.width , interpolation=1)                                    

这个warning就是说参数不能在传数字了了,应该填入InterpolationMode ,查看源码,torchvision说下一个版本更新,会弃用数字参数,应该填入枚举值。目前是兼容两种写法,官方转化数字成枚举值的代码如下:

def _interpolation_modes_from_int(i: int) -> InterpolationMode:
	inverse_modes_mapping = {
   	0: InterpolationMode.NEAREST,
   	2: InterpolationMode.BILINEAR,
   	3: InterpolationMode.BICUBIC,
    4: InterpolationMode.BOX,
   	5: InterpolationMode.HAMMING,
   	1: InterpolationMode.LANCZOS,        
   	}
    return inverse_modes_mapping[i]

部分图像插值算法如下:
[链接]
最近邻插值

双线性插值

Lanzoc插值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值