def extraction(self, data): # extracting 40 features using sparse filtering sp = SparseFiltering(self.num_feature_extract) feature_set = sp.fit_transform(data) # fig = plt.figure() # ax = fig.add_subplot(111, projection='3d') # ax.scatter(feature_set[:, 0], feature_set[:, 1], feature_set[:, 2], c=label[:, 0]) # ax.set_xlabel('feature 1') # ax.set_ylabel('feature 2') # ax.set_zlabel('feature 3') # plt.title('SP visulization') # plt.show() return feature_set
faces_centered.reshape(n_samples, 64, 64) # Reshaping to 64*64 pixel print("Dataset consists of %d faces" % n_samples) ############################################################################### # Extract n_patches patches randomly from each image patches = [ extract_patches_2d(faces_centered[i], (patch_width, patch_width), max_patches=n_patches, random_state=i) for i in range(n_samples) ] patches = np.array(patches).reshape(-1, patch_width * patch_width) ############################################################################### estimator = \ SparseFiltering(n_features=n_features, maxfun=maxfun, iprint=iprint) features = estimator.fit_transform(patches) # ############################################################################# # Plot weights of features pl.figure(0, figsize=(12, 10)) pl.subplots_adjust(left=0.01, bottom=0.01, right=0.99, top=0.95, wspace=0.1, hspace=0.4) for i in range(estimator.w_.shape[0]): pl.subplot(int(np.sqrt(n_features)), int(np.sqrt(n_features)), i + 1) pl.pcolor(estimator.w_[i].reshape(patch_width, patch_width), cmap=pl.cm.gray)