PIL:Python Image Library是Python自带的图片处理库,其保存的图像文件可以叫作PIL_image,是一种特殊结构。在Pytorch中,开发团队为了解决图像处理的性能瓶颈问题,改写而来PIL_image类,简化了一些信息,就成了acc_image这个类。简化的accimage对象除了数据以外的无效成员,可以优化空间和处理速度。
accimage模仿PIL API,利用Intel IPP加速图像加载器和预处理器,可用作torchvision的后端,已经实现Image.resize
、Image.crop
、Image.transpose
等函数。
ACCimage使用的是Intel IPP Library,一般情况下会比Python Image Library块,只不过很少有项目支持。Python Image Library除了基本的数据外,还存了诸如palette、category、pyaccess等很多别的内容。
torchvision的__init__.py
文件中:
def set_image_backend(backend):
"""
Specifies the package used to load images.
Args:
backend (string): Name of the image backend. one of {'PIL', 'accimage'}.
The :mod:`accimage` package uses the Intel IPP library. It is
generally faster than PIL, but does not support as many operations.
"""
global _image_backend
if backend not in ['PIL', 'accimage']:
raise ValueError("Invalid backend '{}'. Options are 'PIL' and 'accimage'"
.format(backend))
_image_backend = backend
PIL_image中Image
类的定义:
class Image(object):
"""
This class represents an image object. To create
:py:class:`~PIL.Image.Image` objects, use the appropriate factory
functions. There's hardly ever any reason to call the Image constructor
directly.
* :py:func:`~PIL.Image.open`
* :py:func:`~PIL.Image.new`
* :py:func:`~PIL.Image.frombytes`
"""
def __init__(self):
# FIXME: take "new" parameters / other image?
# FIXME: turn mode and size into delegating properties?
self.im = None
self.mode = ""
self._size = (0, 0)
self.palette = None
self.info = {}
self.category = NORMAL
self.readonly = 0
self.pyaccess = None
参考资料
What is accimage? #12
Pytorch 中的accimage
pytorch/accimage