Ask Question
Asked 1 year, 6 months ago
Active 3 months ago
Viewed 38k times
68
I have started learning Tensorflow. I am using Pycharm and my environment is Ubuntu 16.04. I am following the tutorial. I cross check the nump. It is up-to-date. I don't know the reason of this error.
from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths'
Need hint to resolve this error. Thank you.
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]
share improve this question follow
44k2323 gold badges118118 silver badges173173 bronze badges
asked Jan 17 '19 at 17:23
75311 gold badge55 silver badges1010 bronze badges
-
4
Take a look at github.com/scikit-image/scikit-image/issues/3586 – cdarke Jan 17 '19 at 17:29
7 Answers
100
I updated my skimage package.
pip install --upgrade scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
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
share improve this answer follow
answered Jan 18 '19 at 18:58
1,25211 gold badge66 silver badges1313 bronze badges
5
scikit-image 0.14.2 worked with numpy 1.16.3. I installed numpy first and then installed scikit image
share improve this answer follow
answered Apr 23 '19 at 12:33
5111 silver badge11 bronze badge
-
now the previous error is gone but getting this new error: Got this error ImportError: cannot import name 'img_as_float32'. Using Version of Numpy: 1.17.0 & skimage: 0.13.0 – Yogesh Aug 24 '19 at 7:03
3
pip install scikit-image==0.14.2 && pip install numpy==1.15
Ref: Here
share improve this answer follow
answered Sep 27 '19 at 11:02
7911 silver badge44 bronze badges
2
I had the same error, I did the following steps:
uninstall scikit-image
pip uninstall scikit-image
or
conda uninstall scikit-image
and then
pip install scikit-image
or
conda install -c conda-forge scikit-image
share improve this answer follow
answered Apr 29 '19 at 16:59
9111 silver badge33 bronze badges
-
After following the above steps getting this error: ImportError: cannot import name 'img_as_float32'. Using Version of Numpy: 1.17.0 & skimage: 0.13.0, Python 3 – Yogesh Aug 24 '19 at 7:03
-
If you are in a jupyter notebook, do not forget to add the --y argument, like !conda uninstall scikit-image --y or !conda install -c conda-forge scikit-image --y – Ivan Apr 10 at 14:54
For me the magic dependency was:
pip install scikit-image==0.13.1
pip install numpy==1.15
For python 3.5 and python 3.6
share improve this answer follow
answered Mar 30 at 15:57
1122 bronze badges
upgrade scikit-image to latest, OR downgrade NumPy to 1.15.
pip install -U scikit-image
or
pip install numpy==1.15
if the pip isn't latest. You may need this:
python -m pip install --upgrade pip
refer to Getting ImportError: cannot import name '_validate_lengths' #3906 .