ebookML_src icon indicating copy to clipboard operation
ebookML_src copied to clipboard

Lỗi thư viện scipy trong thuật toán PCA (chương 21) do đã bỏ imread()

Open nguyenthanhnhon opened this issue 5 years ago • 1 comments

Mình chạy thử code thuật toán PCA để nhận diện khuôn mặt, nhưng đến dòng X[:, cnt] = misc.imread(fn).reshape(D) thì báo lỗi do thư viện Scipy từ phiên bản 1.0.0 đã remove method misc.imread(). Trên trang Scipy có đề nghị dùng thư viện imageio.imread() để thay thế, nhưng thư viện này lại không có hàm reshape() nên mình chưa biết làm thế nào

import numpy as np
from scipy import misc
np.random.seed(1)

path = '/home/nhonnt/Documents/vicohub_lab/PCA/YALE/faces/'
ids = range(1, 16)
states = ['centerlight', 'glasses', 'happy', 'leftlight', 'noglasses', 'normal', 'rightlight', 'sad', 'sleepy', 'surprised', 'wink']
prefix = 'subject'
surfix = '.pgm'

h, w, K = 116, 98, 100 # hight, weight, new dim
D = h * w
N = len(states)*15

X = np.zeros((D, N))
cnt = 0
for person_id in range(1, 16):
    for state in states:
        fn = path + prefix + str(person_id).zfill(2) + '.' + state + surfix
        print(fn)
        X[:, cnt] = misc.imread(fn).reshape(D)
        cnt += 1

from sklearn.decomposition import PCA
pca = PCA(n_components=K)
pca.fit(X.T)

U = pca.components_.T

nguyenthanhnhon avatar Sep 13 '19 00:09 nguyenthanhnhon

Bạn thử build docker lại như hướng dẫn rồi chạy xem thế nào: https://github.com/tiepvupsu/ebookML_src

tiepvupsu avatar Sep 13 '19 01:09 tiepvupsu