caffe: TypeError: _open() got an unexpected keyword argument ‘as_grey‘

通过 caffe 的 python 接口测试模型分类出现如下错误,TypeError: _open() got an unexpected keyword argument 'as_grey'

python classify-alexnet.py --gpu test.jpg result

...

I1005 15:32:11.174566 31243 net.cpp:244] This network produces output prob
I1005 15:32:11.174882 31243 net.cpp:257] Network initialization done.
I1005 15:32:11.199013 31243 upgrade_proto.cpp:79] Attempting to upgrade batch norm layers using deprecated params: /home/user/densenet121.caffemodel
I1005 15:32:11.199146 31243 upgrade_proto.cpp:82] Successfully upgraded batch norm layers using deprecated params.
I1005 15:32:11.199154 31243 net.cpp:746] Ignoring source layer label_data_1_split
I1005 15:32:11.205960 31243 net.cpp:746] Ignoring source layer fc6_fc6_0_split
I1005 15:32:11.205986 31243 net.cpp:746] Ignoring source layer loss
I1005 15:32:11.205992 31243 net.cpp:746] Ignoring source layer accuracy/top1
I1005 15:32:11.206010 31243 net.cpp:746] Ignoring source layer accuracy/top5
Loading file: test.jpg
Traceback (most recent call last):
  File "classify-alexnet.py", line 169, in 
    main(sys.argv)
  File "classify-alexnet.py", line 137, in main
    inputs = [caffe.io.load_image(args.input_file)]
  File "/home/user/caffe-cudnn-nccl-py3/python/caffe/io.py", line 302, in load_image
    img = skimage.img_as_float(skimage.io.imread(filename, as_grey=not color)).astype(np.float32)
  File "/home/user/.conda/envs/py36.caffe.cuda90/lib/python3.6/site-packages/skimage/io/_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "/home/user/.conda/envs/py36.caffe.cuda90/lib/python3.6/site-packages/skimage/io/manage_plugins.py", line 209, in call_plugin
    return func(*args, **kwargs)
  File "/home/user/.conda/envs/py36.caffe.cuda90/lib/python3.6/site-packages/skimage/io/_plugins/imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "/home/user/.conda/envs/py36.caffe.cuda90/lib/python3.6/site-packages/imageio/core/functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "/home/user/.conda/envs/py36.caffe.cuda90/lib/python3.6/site-packages/imageio/core/functions.py", line 186, in get_reader
    return format.get_reader(request)
  File "/home/user/.conda/envs/py36.caffe.cuda90/lib/python3.6/site-packages/imageio/core/format.py", line 170, in get_reader
    return self.Reader(self, request)
  File "/home/user/.conda/envs/py36.caffe.cuda90/lib/python3.6/site-packages/imageio/core/format.py", line 221, in __init__
    self._open(**self.request.kwargs.copy())
TypeError: _open() got an unexpected keyword argument 'as_grey'

根据错误信息发现在 caffe 提供的 python/caffe/io.py 中,302行 skimage.io.imread() 调用参数 “as_grey” 实际应当修改为 “as_gray”,原因应该是 scikit-image 的 0.17.2 版本修改了参数名称。

283 ## Image IO
284 
285 def load_image(filename, color=True):
286     """
287     Load an image converting from grayscale or alpha as needed.
288 
289     Parameters
290     ----------
291     filename : string
292     color : boolean
293         flag for color format. True (default) loads as RGB while False
294         loads as intensity (if image is already grayscale).
295 
296     Returns
297     -------
298     image : an image with type np.float32 in range [0, 1]
299         of size (H x W x 3) in RGB or
300         of size (H x W x 1) in grayscale.
301     """
302     img = skimage.img_as_float(skimage.io.imread(filename, as_grey=not color)).astype(np.float32)
303     if img.ndim == 2:
304         img = img[:, :, np.newaxis]
305         if color:
306             img = np.tile(img, (1, 1, 3))
307     elif img.shape[2] == 4:
308         img = img[:, :, :3]
309     return img

以下是相关程序库版本:

$ cdaplst | grep scikit-image
scikit-image              0.17.2           py36h7c3b610_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
$ python -V
Python 3.6.11
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

 

你可能感兴趣的:(Caffe)