About some mistakes made by running the code of "Face Recognition Program Based on Extreme Learning Machine ELM"

Code source Face recognition program based on
extreme learning machine ELM Thanks for the sharing of the article owner

my environment is

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

1. Run the code block directly, it prompts "unknown reference import hpelm"

This is because my Python environment does not have hpelm installed, running the code pip install hpelm. The first installation was unsuccessful, and the query found that it may be a pip version problem. After upgrading the pip version, running it pip3 install hpelm, the installation was successful. The installation commands used twice are different. I don’t know if the hpelm was successfully installed because the pip version was upgraded.

2. Prompt 'import cv2' error

After installing hpelm, run the code again, prompting the above error, because opencv is not installed in my environment, run

  1. pip install numpy Matplotlib
  2. pip install opencv-pythonInstallation is successful

3. Prompt the numpy version is wrong

Run the code again, the numpy version is wrong, and the error is displayed

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

Online prompts to upgrade the numpy version, the method:

  1. runpip uninstall numpy
  2. Run and pip install -U numpy
    install successfully.

4. Prompt error 'AssertionError: X has wrong dimensionality: expected 10000, found 1'

The error is as follows:

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:\Users\caichangqing\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\hpelm\elm.py", line 182, in train
X, T = self._checkdata(X, T)
File "C:\Users\caichangqing\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\hpelm\elm.py", line 533, in _checkdata
(self.nnet.inputs, X.shape[1])
AssertionError: X has wrong dimensionality: expected 10000, found 1

Due to the path problem, the format of the path in the code is 'D:\abc\abc\a', and the middle '' symbol is regarded as an escape character, resulting in a path error, which should be changed to

  • D:\\abc\\abc\\a
  • or D:/abc/abc/a

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

The error is as follows:

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

In the reference of the code, importing opencv is 'import opencv as cv2', my environment is 'python 3.6', it should be imported using 'import cv2'

6. Error in image reading

The error is as follows:

OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in cv::resize, file C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp, line 4044
Traceback (most recent call last):
File "train_hpelm.py", line 15, in

After trying a lot, I finally found that there was a problem with the face library I downloaded. In the same environment, cv2.imread() can read other pictures, but cannot read the face library pictures I downloaded. After cv2.imread() reads The return value is None. At the same time, all images that cannot be read correctly will prompt this error.
(Later the classmates said that cv2.imread can't read gif pictures, I downloaded this format)

7. Just change the name of the newly downloaded library

The download address of the yale face library I use

#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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325196742&siteId=291194637