在跑See-in-the-dark模型的时候出现了这个问题。
根据Scipy官方文档的说法,scipy.misc.toimage在1.2.1之后的版本中已经被移除了,所以要做的第一件是就是降级:
pip install scipy==1.2.1
如果你下载了之后还是用不了的话,可以先看看这个库的属性:
dir(scipy.misc)['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_comb', '_fact', '_fact2', '_factk', '_info', '_lsm', '_msg', '_pade', '_source', '_who', 'absolute_import', 'ascent', 'central_diff_weights', 'comb', 'derivative', 'division', 'doccer', 'electrocardiogram', 'face', 'factorial', 'factorial2', 'factorialk', 'info', 'logsumexp', 'np', 'pade', 'print_function', 'source', 'test', 'who']
怎么还是没有'toimage'呢?
通过翻阅misc的文件,我发现toimage被写在了pilutil.py文件里,而这个文件的开头有说明:A collection of image utilities using the Python Imaging Library (PIL).
Note that PIL is not a dependency of SciPy and this module is not available on systems that don't have PIL installed.
所以只有安装了pillow之后,才会显示这个属性。
pip install pillow
现在再来看scipy.misc的属性就有了:['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_comb', '_fact', '_fact2', '_factk', '_info', '_lsm', '_msg', '_pade', '_source', '_who', 'absolute_import', 'ascent', 'bytescale', 'central_diff_weights', 'comb', 'derivative', 'division', 'doccer', 'electrocardiogram', 'face', 'factorial', 'factorial2', 'factorialk', 'fromimage', 'imfilter', 'imread', 'imresize', 'imrotate', 'imsave', 'imshow', 'info', 'logsumexp', 'np', 'pade', 'print_function', 'source', 'test', 'toimage', 'who']