ImportError: cannot import name '_validate_lengths'

When import albumentations library error:
ImportError: CAN not Import name '_validate_lengths'
environment: tensorflow 1.15 numpy 1.18.0
reason is dependent numpy version does not support, nor can reduce the release, estimated tensorflow together to reduce the job. .

Solution:
1.numpy down version 1.16.0
2. Locate arraycrop.py,
then

import numpy as np
from numpy.lib.arraypad import _validate_lengths

change into

import numpy as np
from distutils.version import LooseVersion as Version
old_numpy = Version(np.__version__) < Version('1.16')
if old_numpy:
    from numpy.lib.arraypad import _validate_lengths
else:
    from numpy.lib.arraypad import _as_pairs

Restart the environment!
OK

Note

I modified at ambient numpy 1.18 will complain:
No Module named 'numpy.testing.decorators'
so it is still lower in numpy modify ~ ~ ~

Published 29 original articles · won praise 12 · views 10000 +

Guess you like

Origin blog.csdn.net/c2250645962/article/details/103881094