TypeError: self._open() got an unexpected keyword argument 'as_grey' python

TypeError: self._open() got an unexpected keyword argument 'as_grey' python

我的一位同事在对图像进行分类时 python 服务出错。 下面是错误跟踪日志

 File "nsfw.py", line 7, in <module>
score = classifier.get_score('8.jpg')
 File "/home/arunsharma/.local/lib/python3.6/site-packages/open_nsfw_python3/__init__.py", line 104, in get_score
image_data, caffe_transformer=caffe_transformer, caffe_net=nsfw_net, output_layers=['prob'])


File "/home/arunsharma/.local/lib/python3.6/site-packages/open_nsfw_python3/__init__.py", line 52, in caffe_preprocess_and_compute
    image = caffe.io.load_image(img_data_rs)
  File "/usr/lib/python3/dist-packages/caffe/io.py", line 301, in load_image
    img = skimage.img_as_float(skimage.io.imread(filename, as_grey=not color)).astype(np.float32)
  File "/home/arunsharma/.local/lib/python3.6/site-packages/skimage/io/_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "/home/arunsharma/.local/lib/python3.6/site-packages/skimage/io/manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "/home/arunsharma/.local/lib/python3.6/site-packages/skimage/io/_plugins/imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "/home/arunsharma/.local/lib/python3.6/site-packages/imageio/core/functions.py", line 264, in imread
    reader = read(uri, format, "i", **kwargs)
  File "/home/arunsharma/.local/lib/python3.6/site-packages/imageio/core/functions.py", line 186, in get_reader
    return format.get_reader(request)
  File "/home/arunsharma/.local/lib/python3.6/site-packages/imageio/core/format.py", line 164, in get_reader
    return self.Reader(self, request)
  File "/home/arunsharma/.local/lib/python3.6/site-packages/imageio/core/format.py", line 214, in __init__
    self._open(**self.request.kwargs.copy())
TypeError: _open() got an unexpected keyword argument 'as_grey'

Here是他用过的库。他首先安装了caffe库并升级了skimage库。但仍然没有运气。

如有任何帮助,我们将不胜感激。

代码:

from open_nsfw_python3 import NSFWClassifier

classifier = NSFWClassifier()

score = classifier.get_score('image.jpg')

print(score)

他在执行 get_score 时得到错误。

pycaffe依赖skimage做图像预处理。随着 skimage 在版本中的发展,他们决定将一些函数参数从 as_grey 重命名为 as_gray.

然而,Caffe 仍然使用 as_grey

https://github.com/BVLC/caffe/blob/9b891540183ddc834a02b2bd81b31afae71b2153/python/caffe/io.py#L302

您有两个选择,安装旧版本的 skimage,或更改 pycaffe 中的那行代码,以使用 as_gray