ImportError:无法导入名称“ _validate_lengths”


68

我已经开始学习Tensorflow。我正在使用Pycharm,环境是Ubuntu 16.04。我正在学习本教程。我交叉检查了小瘤。它是最新的。我不知道此错误的原因。

从numpy.lib.arraypad import _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]

Answers:


102

我更新了skimage软件包。

pip install --upgrade scikit-image

问题解决了。这是Skimage版本的问题,已在0.14.2中解决。PLus,此版本非常稳定。

    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

5

scikit-image 0.14.2与numpy 1.16.3一起使用。我先安装了numpy,然后安装了scikit映像


现在,先前的错误消失了,但是得到了这个新的错误:得到了这个错误ImportError:无法导入名称'img_as_float32'。使用Numpy版本:1.17.0和skimage:0.13.0
Yogesh,

3

pip install scikit-image==0.14.2 && pip install numpy==1.15

参考:这里


2

我遇到了同样的错误,我执行了以下步骤:

卸载scikit-image

pip uninstall scikit-image

要么

conda uninstall scikit-image

接着

pip install scikit-image

要么

conda install -c conda-forge scikit-image

按照上述步骤操作后,出现此错误:ImportError:无法导入名称'img_as_float32'。使用Numpy版本:1.17.0和skimage:0.13.0,Python 3
Yogesh,

如果您使用的是Jupyter笔记本,请不要忘记添加--y参数,例如!conda卸载scikit-image --y或!conda install -c conda-forge scikit-image --y
Ivan

0

对我来说,魔术依赖是:

pip install scikit-image==0.13.1
pip install numpy==1.15

对于python 3.5和python 3.6



-1

由于同时安装了两个版本,我似乎也遇到了相同的问题。

我通过多次卸载scikit-image直到没有任何问题来解决了这个问题。

pip uninstall scikit-image

然后重新安装:

pip uninstall scikit-image

它为我工作。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.