在升级了numpy之后sklearn-image的引用报告了以下错误:
Traceback (most recent call last):
File "scripts/demo_5.py", line 15, in
from predictors.recon1_predictor import Recon1Predictor
File "/home/users/XXXXXXX/predictors/recon1_predictor.py", line 18, in
from skimage.transform import estimate_transform, warp
File "/home/users/bingqian.geng/anaconda3/lib/python3.7/site-packages/skimage/__init__.py", line 157, in
from .util.dtype import *
File "/home/users/XXXXXXX/anaconda3/lib/python3.7/site-packages/skimage/util/__init__.py", line 8, in
from .arraycrop import crop
File "/home/users/XXXXXXX/anaconda3/lib/python3.7/site-packages/skimage/util/arraycrop.py", line 8, in
from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' (/home/users/bingqian.geng/anaconda3/lib/python3.7/site-packages/numpy/lib/arraypad.py)
这个问题的解决办法是
pip install numpy==1.15
原因是,在numpy升级的时候这个函数竟然重写了,虽然一般的调用没有什么毛病,但是sklearn-images调用了一些较为底层 的接口就导致了这个问题。
GitHub numpy更改记录:https://github.com/numpy/numpy/commit/a4b96ad7649281de2c3a41292fcbab4c77c0743d#diff-4fcddc9140fbe901655b3e1bd484205c