我已经开始学习Tensorflow。我正在使用Pycharm,我的环境是Ubuntu 16.04。我正在关注tutorial。我交叉检查了小瘤。它是最新的。我不知道此错误的原因。
从numpy.lib.arraypad导入_validate_lengths
ImportError:无法导入名称“ _validate_lengths”
需要提示以解决此错误。谢谢。
import tensorflow as tf
from skimage import transform
from skimage import data
import matplotlib.pyplot as plt
import os
import numpy as np
from skimage.color import rgb2gray
import random
#listdir: This method returns a list containing the names of the entries in the directory given by path.
# Return True if path is an existing directory
def load_data(data_dir):
# Get all subdirectories of data_dir. Each represents a label.
directories = [d for d in os.listdir(data_dir)
if os.path.isdir(os.path.join(data_dir, d))]
# Loop through the label directories and collect the data in
# two lists, labels and images.
labels = []
images = []
for d in directories:
label_dir = os.path.join(data_dir, d)
file_names = [os.path.join(label_dir, f)
for f in os.listdir(label_dir)
if f.endswith(".ppm")]
for f in file_names:
images.append(data.imread(f))
labels.append(int(d))
return images, labels
ROOT_PATH = "/home/tahir/PhD Study/Traffic Signs Using Tensorflow/"
train_data_dir = os.path.join(ROOT_PATH, "TrafficSigns/Training")
test_data_dir = os.path.join(ROOT_PATH, "TrafficSigns/Testing")
images, labels = load_data(train_data_dir)
# Print the `images` dimensions
print(images.ndim)
# Print the number of `images`'s elements
print(images.size)
# Print the first instance of `images`
images[0]
答案 0 :(得分:68)
I updated my skimage package.
pip install --upgrade scikit-image
And the problem was solved. It's a problem of version of Skimage, which is solved in 0.14.2. PLus, this version is quite stable.
Installing collected packages: dask, scikit-image
Found existing installation: dask 0.19.1
Uninstalling dask-0.19.1:
Successfully uninstalled dask-0.19.1
Found existing installation: scikit-image 0.13.0
Uninstalling scikit-image-0.13.0:
Successfully uninstalled scikit-image-0.13.0
Successfully installed dask-1.0.0 scikit-image-0.14.2
答案 1 :(得分:3)
pip install scikit-image==0.14.2 && pip install numpy==1.15
参考:Here
答案 2 :(得分:2)
scikit-image 0.14.2与numpy 1.16.3一起使用。我先安装了numpy,然后安装了scikit映像
答案 3 :(得分:0)
我有同样的错误,我执行了以下步骤:
卸载scikit映像
pip uninstall scikit-image
或
conda uninstall scikit-image
然后
pip install scikit-image
或
conda install -c conda-forge scikit-image
答案 4 :(得分:0)
对我来说,魔术依赖是:
pip install scikit-image==0.13.1
pip install numpy==1.15
对于python 3.5和python 3.6
答案 5 :(得分:0)
将scikit映像升级到最新版本,或者 将NumPy降级为1.15。
https://github.com/pyinstaller/pyinstaller/archive/develop.zip
或
pip install -U scikit-image
如果该点不是最新的。您可能需要这个:
pip install numpy==1.15
请参阅Getting ImportError: cannot import name '_validate_lengths' #3906。
答案 6 :(得分:-1)
由于两个版本同时安装,我似乎也遇到了相同的问题。
我通过多次卸载scikit-image直到没有任何问题来解决了这个问题。
pip uninstall scikit-image
然后重新安装:
pip uninstall scikit-image
对我有用。