• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

python - ImportError:无法导入名称'_validate_lengths'

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

问题描述

学习Tensorflow遇到以下问题(我使用Pycharm,环境是Ubuntu 16.04)。我不知道此错误的原因。

from numpy.lib.arraypad import _validate_lengths

ImportError: cannot import name ‘_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]

 

最佳思路

我更新了skimage软件包。

pip install --upgrade scikit-image

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

    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: cannot import name ‘_validate_lengths’

 


鲜花

握手

雷人

路过

鸡蛋
专题导读
上一篇:
python - Tensorflow在jupyter中设置CUDA_VISIBLE_DEVICES发布时间:2022-05-14
下一篇:
Python的Jupyter Notebook入门教程发布时间:2022-05-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap