本文介绍了ImportError:无法导入名称"_validate_lengths"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经开始学习Tensorflow.我正在使用Pycharm,我的环境是Ubuntu 16.04.我正在关注教程.我交叉检查了小瘤.它是最新的.我不知道此错误的原因.
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.
ImportError:无法导入名称"_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]
推荐答案
我更新了skimage软件包.
I updated my skimage package.
pip install --upgrade scikit-image
问题解决了.这是Skimage版本的问题,已在0.14.2中解决. PLus,此版本非常稳定.
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
这篇关于ImportError:无法导入名称"_validate_lengths"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!