zoukankan      html  css  js  c++  java
  • 关于运行“基于极限学习机ELM的人脸识别程序”代码犯下的一些错误

    代码来源 基于极限学习机ELM的人脸识别程序
    感谢文章主的分享

    我的环境是

    • win10
    • anaconda Command line client (version 1.6.5)(conda 4.3.30)
    • tensorflow-gpu 1.1.0
    • python 3.6.2

    1. 直接运行代码块,提示“未知引用 import hpelm"

    这是因为我的Python环境没有安装hpelm导致的,运行代码pip install hpelm。第一次安装没有成功,查询发现可能是pip版本问题,升级了pip版本,运行pip3 install hpelm,安装成功,两次使用的安装命令不同,不知道是不是因为升级了pip版本才安装hpelm成功的。

    2. 提示‘import cv2’错误

    安装hpelm后,再次运行代码,提示上述错误,因为我的环境没有安装opencv,运行

    1. pip install numpy Matplotlib
    2. pip install opencv-python安装成功即可

    3. 提示numpy版本不对

    再次运行代码,提示numpy版本不对,提示错误

    RuntimeError: module compiled against API version 0xc but this version of numpy is 0xa

    网上提示升级numpy版本,方法:

    1. 运行pip uninstall numpy
    2. 运行pip install -U numpy
      安装成功即可。

    4. 提示错误'AssertionError: X has wrong dimensionality: expected 10000, found 1'

    错误如下:

    Traceback (most recent call last):
    File "train_hpelm.py", line 38, in <module>
    elm.train(np.array(input_data),np.array(output_data))
    File "C:UserscaichangqingAppDataLocalcondacondaenvs ensorflowlibsite-packageshpelmelm.py", line 182, in train
    X, T = self._checkdata(X, T)
    File "C:UserscaichangqingAppDataLocalcondacondaenvs ensorflowlibsite-packageshpelmelm.py", line 533, in _checkdata
    (self.nnet.inputs, X.shape[1])
    AssertionError: X has wrong dimensionality: expected 10000, found 1

    由于路径问题,代码中路径的格式’D:abcabca',中间''符号被当成转义字符,造成路径错误,应该改成

    • D:\abc\abc\a
    • 或者 D:/abc/abc/a

    5. AttributeError: module 'opencv' has no attribute 'resize'

    错误如下:

    AttributeError: module 'opencv' has no attribute 'resize'

    在代码的引用中,导入opencv是'import opencv as cv2',我的环境是'python 3.6',应该使用'import cv2'导入

    6. 读入图片错误

    错误如下:

    OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in cv::resize, file C:projectsopencv-pythonopencvmodulesimgprocsrc esize.cpp, line 4044
    Traceback (most recent call last):
    File "train_hpelm.py", line 15, in
    manimg = cv2.resize(cv2.imread(file_path, cv2.IMREAD_GRAYSCALE),(100, 100),interpolation=cv2.INTER_CUBIC)
    cv2.error: C:projectsopencv-pythonopencvmodulesimgprocsrc esize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize

    试了很多,最后发现我下载的人脸库有问题,同样环境下,cv2.imread()可以读取别的图片,不能读取我下载的人脸库图片,cv2.imread()读取后返回值是None。同时,所有不能正确读入图片都会提示该错误。
    (后来同学说cv2.imread不能读取gif图片,我下的是这个格式的)

    7. 新下载的库,改名就行了

    我使用的yale人脸库下载地址

    #coding=utf-8  
    import os
    path = "D:\tensorflow\face\yale" #更改为你自己的人脸库路径
    count = 1
    flag = 1
    for i in range(1,166):
       flag = i%11
       add_pre=lambda x:'0'+str(x) if len(str(x))==1 else str(x)      #加前缀
       if(flag == 0 ):
    	  flag = 11
       files = os.path.join(path, 's{}.bmp'.format(i))
       if(os.path.isfile(files)):
           	filename=os.path.splitext(files)[0];#文件名
    	  filetype=os.path.splitext(files)[1];#文件扩展名
    	  Newdir=os.path.join(path,'subject{}_{}'.format(add_pre(count),flag)+filetype);#新的文件路径
    	  os.rename(files,Newdir)#重命名
       if(flag == 11): count += 1
  • 相关阅读:
    解决SharePoint 文档库itemadded eventhandler导致的上传完成后,编辑页面保持报错的问题,错误信息为“该文档已经被编辑过 the file has been modified by...”
    解决SharePoint 2013 designer workflow 在发布的报错“负载平衡没有设置”The workflow files were saved but cannot be run.
    随机实例,随机值
    Spring4笔记
    struts2笔记(3)
    struts2笔记(2)
    获取文本的编码类型(from logparse)
    FileUtil(from logparser)
    DateUtil(SimpleDateFormat)
    struts2笔记
  • 原文地址:https://www.cnblogs.com/donfaquir/p/8974822.html
Copyright © 2011-2022 走看看