• kears库中对样本图片resize的原理(target_size)


    link: https://blog.csdn.net/qq_41775810/article/details/82798906

    调用keras库去训练样本的时候,经常会用target_size吧图片resize自己想要的形状继续训练,可是需要预测的时候想单张把图片放进去预测,需要重复相同的resize步骤,于是看了源码,在image.py中有找到了方法

    def load_img(path, grayscale=False, color_mode='rgb', target_size=None,
    interpolation='nearest'):
    """Loads an image into PIL format.

    # Arguments
    path: Path to image file.
    color_mode: One of "grayscale", "rbg", "rgba". Default: "rgb".
    The desired image format.
    target_size: Either `None` (default to original size)
    or tuple of ints `(img_height, img_width)`.
    interpolation: Interpolation method used to resample the image if the
    target size is different from that of the loaded image.
    Supported methods are "nearest", "bilinear", and "bicubic".
    If PIL version 1.1.3 or newer is installed, "lanczos" is also
    supported. If PIL version 3.4.0 or newer is installed, "box" and
    "hamming" are also supported. By default, "nearest" is used.

    # Returns
    A PIL Image instance.

    # Raises
    ImportError: if PIL is not available.
    ValueError: if interpolation method is not supported.
    """
    if grayscale is True:
    warnings.warn('grayscale is deprecated. Please use '
    'color_mode = "grayscale"')
    color_mode = 'grayscale'
    if pil_image is None:
    raise ImportError('Could not import PIL.Image. '
    'The use of `array_to_img` requires PIL.')
    img = pil_image.open(path)
    if color_mode == 'grayscale':
    if img.mode != 'L':
    img = img.convert('L')
    elif color_mode == 'rgba':
    if img.mode != 'RGBA':
    img = img.convert('RGBA')
    elif color_mode == 'rgb':
    if img.mode != 'RGB':
    img = img.convert('RGB')
    else:
    raise ValueError('color_mode must be "grayscale", "rbg", or "rgba"')
    if target_size is not None:
    width_height_tuple = (target_size[1], target_size[0])
    if img.size != width_height_tuple:
    if interpolation not in _PIL_INTERPOLATION_METHODS:
    raise ValueError(
    'Invalid interpolation method {} specified. Supported '
    'methods are {}'.format(
    interpolation,
    ", ".join(_PIL_INTERPOLATION_METHODS.keys())))
    resample = _PIL_INTERPOLATION_METHODS[interpolation]
    img = img.resize(width_height_tuple, resample)
    return img

    可以看出,是用pil中nearest(默认)的模式resize的,所以只需要按照相同的方法resize就OK了
    ————————————————
    版权声明:本文为CSDN博主「qq_41775810」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_41775810/article/details/82798906

  • 相关阅读:
    行业基本面量化之商业银行
    [茶思]另类数据及其在投资中的应用
    [茶思]机器学习与宏观基本面方法在债券定价中的应用
    [宏观追踪]美国2020年2月
    [饭想]可转债市场的发展趋势
    [读论文]谷歌搜索量与个人投资者交易行为
    [读论文]基金评级及其激励
    [读论文]懒价格
    [宏观追踪]中国2020年2月
    虚拟机nat-网络认知-更正(vmware 的nat规则设置完网关,虚拟机设置自己网络就完事了。物理机相当于双网卡 物理和vmware8,8只是为了物理机xshell连接虚拟机,禁用了虚拟机照样上网)
  • 原文地址:https://www.cnblogs.com/xiexiaokui/p/12109337.html
Copyright © 2020-2023  润新知