【问题标题】:Open WebP images in GCE Deep Learning VM在 GCE 深度学习 VM 中打开 WebP 图像
【发布时间】:2020-02-11 04:10:17
【问题描述】:

在python代码中,我需要处理webp图像。但是当我尝试用 python PIL 模块打开它时,我有一个错误: OSError: cannot identify image file 'my_image.webp

我的深度学习映像是从 GCP Marketplace VM(tensorflow 映像)创建的,但 webp 格式似乎没有在枕头级别“激活”。

python默认支持webp格式吗? 我需要在 VM 上做什么/安装/导入才能使用 python PIL 打开 webp 图像?

我的python代码步骤:

>>>import PIL
​
>>>print(PIL.__version__)
6.0.0.post0

>>>from PIL import features
>>>print (features.check_module('webp'))
False

>>> PIL.Image.open('my_image.webp')
/usr/local/lib/python3.5/dist-packages/PIL/Image.py:2703: UserWarning: image file could not be identified because WEBP support not installed
  warnings.warn(message)
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-4-99a62d35da67> in <module>
----> 1 PIL.Image.open('BATIMENT0000000045936174_flatRoof.webp')

/usr/local/lib/python3.5/dist-packages/PIL/Image.py in open(fp, mode)
   2703         warnings.warn(message)
   2704     raise IOError("cannot identify image file %r"
-> 2705                   % (filename if filename else fp))
   2706 
   2707 #

OSError: cannot identify image file 'my_image.webp'

【问题讨论】:

  • 看起来这些步骤可以为枕头添加 webp 支持:pip uninstall Pillow &amp;&amp;\ pip uninstall Pillow-SIMD &amp;&amp;\ sudo apt install libwebp-dev &amp;&amp;\ pip install Pillow-SIMD 然后需要重新启动 jupyter 内核并且 PIL 能够读取 webp 图像

标签: python-imaging-library webp google-dl-platform


【解决方案1】:

打开 GCP 虚拟机的 JupyterLab UI 并运行终端会话。在终端运行这些命令来安装 webp 库:

pip uninstall Pillow
pip uninstall Pillow-SIMD
sudo apt install libwebp-dev
pip install Pillow-SIMD

重启你的 Jupyter 内核。现在 PIL 可以读取 webp 图像了。

【讨论】:

    【解决方案2】:

    在我的一台服务器上遇到了类似的问题。

    使用了上面提到的命令,但在运行features.check_module('webp')时仍然得到False

    结果是在重新安装 Pillow-SIMD 时,您需要确保您没有使用构建的缓存版本,否则您将无法获得 WEBP 支持。所以将最后一步更改为:pip install Pillow-SIMD --no-cache-dir 为我解决了它。

    我会将此添加为评论,但我没有足够的代表!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-14
      • 2021-06-22
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 2022-09-24
      • 2021-12-06
      • 2017-09-12
      相关资源
      最近更新 更多