din*_*nam 21 python deep-learning google-colaboratory
我在google-colab上运行了fast.ai的lesson1.当我来到这条线
img = plt.imread(f'{PATH}valid/cats/{files[0]}')
plt.imshow(img);
Run Code Online (Sandbox Code Playgroud)
它没有显示图像.相反,我得到一个错误:
AttributeError: module 'PIL.Image' has no attribute 'register_extensions'
可能是什么导致了这个?
Tom*_*ale 10
当我遇到这个问题时,我在Google Colab上.
在安装代码之后torch,添加:
!pip install pillow==4.1.1
%reload_ext autoreload
%autoreload
Run Code Online (Sandbox Code Playgroud)
该%autoreload所以不需要内核重启将重新加载的所有模块.
积分转到这个论坛帖子.
加载模块pillow和所有其他fastai设置后对我有用的是:
# workaround
from PIL import Image
def register_extension(id, extension): Image.EXTENSION[extension.lower()] = id.upper()
Image.register_extension = register_extension
def register_extensions(id, extensions):
for extension in extensions: register_extension(id, extension)
Image.register_extensions = register_extensions
Run Code Online (Sandbox Code Playgroud)
现在不需要运行时重启.
在 colab notebook 的开头运行这 3 行
!pip install Pillow==4.0.0
!pip install PIL
!pip install image
Run Code Online (Sandbox Code Playgroud)
我也在为同样的问题而苦苦挣扎。但这对我有用。 https://pillow.readthedocs.io/en/3.1.x/reference/Image.html
您安装的 Pillow 版本不是最新的。运行以下命令:
import PIL
print(PIL.PILLOW_VERSION)
Run Code Online (Sandbox Code Playgroud)
可能会4.0.0。如果是这样,请运行以下命令:
!pip uninstall Pillow
!pip install Pillow==5.3.0
Run Code Online (Sandbox Code Playgroud)
然后重新启动您的运行时(按CTRL + M .,或Runtime --> Restart runtime从菜单中)。再次运行第一组命令以确保您当前的 PIL 版本为 5.3.0。
下次启动 colab VM 时,请务必注释掉以下两行(即不要运行它们)
\n\n#%reload_ext autoreload <------------\xe2\x80\x94 comment out \n#%autoreload 0 <------------\xe2\x80\x94 comment out\n%matplotlib inline\nRun Code Online (Sandbox Code Playgroud)\n\n为了安全起见,我还重新安装了我的 PIL
\n\n!pip install --no-cache-dir -I pillow\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
13573 次 |
| 最近记录: |