Getting the following error while using scikit-image to read images "AttributeError: 'PngImageFile' object has no attribute '_PngImageFile__frame' "

Getting the following error while using scikit-image to read images "AttributeError: 'PngImageFile' object has no attribute '_PngImageFile__frame' "

我正在使用 scikit-image 从文件夹加载随机图像。后面会用OpenCV做运算..

代码如下(只包含相关部分)

import imageio
import cv2 as cv
import fileinput
from collections import Counter

from data.apple_dataset import AppleDataset
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
from torchvision.models.detection.mask_rcnn import MaskRCNNPredictor
from torchvision.transforms import functional as F

import utility.utils as utils
import utility.transforms as T

from PIL import Image
import skimage.io
from skimage.viewer import ImageViewer
from matplotlib import pyplot as plt
%matplotlib inline

 APPLE_IMAGE_PATH = r"__mypath__\samples\apples\images"

# Load a random image from the images folder
FILE_NAMES = next(os.walk(APPLE_IMAGE_PATH))[2]
random_apple_in_folder = os.path.join(APPLE_IMAGE_PATH, random.choice(FILE_NAMES))
apple_image = skimage.io.imread(random_apple_in_folder)
apple_image_cv = cv.imread(random_apple_in_folder)
apple_image_cv = cv.cvtColor(apple_image_cv, cv.COLOR_BGR2RGB)

错误如下

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-9575eed18f18> in <module>
     11 FILE_NAMES = next(os.walk(APPLE_IMAGE_PATH))[2]
     12 random_apple_in_folder = os.path.join(APPLE_IMAGE_PATH, random.choice(FILE_NAMES))
---> 13 apple_image = skimage.io.imread(random_apple_in_folder)
     14 apple_image_cv = cv.imread(random_apple_in_folder)

    AttributeError: 'PngImageFile' object has no attribute '_PngImageFile__frame'

我该如何从这里开始?我应该改变什么???

这是 Pillow 7.1.0 中的错误。您可以使用 pip install -U pillow 升级 Pillow。有关详细信息,请参阅此错误报告:

https://github.com/scikit-image/scikit-image/issues/4548