栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > Python

报错:Argument interpolation should be of type InterpolationMode instead of int (成功解决)

Python 更新时间:发布时间: 百科书网 趣学号
/home/.../anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py:281: 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. "

错误原因: 原生代码与本地pytorch版本不一致

2020-11-28 nightly release (4ab46e5f7585b86fb2befdc32d22d13635868c4e) · be02dfa3b9 - vision - uniartisan: Git with group

解决方法:修改只需transforms.py 文件中的方法以及相关调用 (成功解决)

一:如 将文件中的  Image.BICUBIC  改为  InterpolationMode.BICUBIC

源代码:

_pil_interpolation_to_str = {
    Image.NEAREST: 'PIL.Image.NEAREST',
    Image.BILINEAR: 'PIL.Image.BILINEAR',
    Image.BICUBIC: 'PIL.Image.BICUBIC',
    Image.LANCZOS: 'PIL.Image.LANCZOS',
    Image.HAMMING: 'PIL.Image.HAMMING',
    Image.BOX: 'PIL.Image.BOX',
}


def _pil_interp(method):
    if method == 'bicubic':
        return Image.BICUBIC
    elif method == 'lanczos':
        return Image.LANCZOS
    elif method == 'hamming':
        return Image.HAMMING
    else:
        # default bilinear, do we want to allow nearest?
        return Image.BILINEAR


_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)

修改后代码:

_pil_interpolation_to_str = {
    InterpolationMode.NEAREST: 'InterpolationMode.NEAREST',
    InterpolationMode.BILINEAR: 'InterpolationMode.BILINEAR',
    InterpolationMode.BICUBIC: 'InterpolationMode.BICUBIC',
    InterpolationMode.LANCZOS: 'InterpolationMode.LANCZOS',
    InterpolationMode.HAMMING: 'InterpolationMode.HAMMING',
    InterpolationMode.BOX: 'InterpolationMode.BOX',
}


def _pil_interp_torch10(method):
    if method == 'bicubic':
        return InterpolationMode.BICUBIC
    elif method == 'lanczos':
        return InterpolationMode.LANCZOS
    elif method == 'hamming':
        return InterpolationMode.HAMMING
    else:
        # default bilinear, do we want to allow nearest?
        return InterpolationMode.BILINEAR


_RANDOM_INTERPOLATION = (InterpolationMode.BILINEAR, InterpolationMode.BICUBIC)

并且添加 InterpolationMode 类(torchvision.transforms.functional — Torchvision 0.10.0 documentationhttps://pytorch.org/vision/stable/_modules/torchvision/transforms/functional.html#InterpolationMode)

二: 其他文件如rand_augment_transform都会调用_pil_interp(method):故仍需同时保留原_pil_interp(method)文件。

def _pil_interp(method):
    if method == 'bicubic':
        return Image.BICUBIC
    elif method == 'lanczos':
        return Image.LANCZOS
    elif method == 'hamming':
        return Image.HAMMING
    else:
        # default bilinear, do we want to allow nearest?
        return Image.BILINEAR

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/268536.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号