本文整理汇总了Python中sklearn.datasets.fetch_lfw_people函数的典型用法代码示例。如果您正苦于以下问题:Python fetch_lfw_people函数的具体用法?Python fetch_lfw_people怎么用?Python fetch_lfw_people使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fetch_lfw_people函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_load_fake_lfw_people
def test_load_fake_lfw_people():
lfw_people = fetch_lfw_people(data_home=SCIKIT_LEARN_DATA,
min_faces_per_person=3,
download_if_missing=False)
# The data is croped around the center as a rectangular bounding box
# around the face. Colors are converted to gray levels:
assert_equal(lfw_people.images.shape, (10, 62, 47))
assert_equal(lfw_people.data.shape, (10, 2914))
# the target is array of person integer ids
assert_array_equal(lfw_people.target, [2, 0, 1, 0, 2, 0, 2, 1, 1, 2])
# names of the persons can be found using the target_names array
expected_classes = ['Abdelatif Smith', 'Abhati Kepler', 'Onur Lopez']
assert_array_equal(lfw_people.target_names, expected_classes)
# It is possible to ask for the original data without any croping or color
# conversion and not limit on the number of picture per person
lfw_people = fetch_lfw_people(data_home=SCIKIT_LEARN_DATA, resize=None,
slice_=None, color=True,
download_if_missing=False)
assert_equal(lfw_people.images.shape, (17, 250, 250, 3))
# the ids and class names are the same as previously
assert_array_equal(lfw_people.target,
[0, 0, 1, 6, 5, 6, 3, 6, 0, 3, 6, 1, 2, 4, 5, 1, 2])
assert_array_equal(lfw_people.target_names,
['Abdelatif Smith', 'Abhati Kepler', 'Camara Alvaro',
'Chen Dupont', 'John Lee', 'Lin Bauman', 'Onur Lopez'])
开发者ID:NelleV,项目名称:scikit-learn,代码行数:30,代码来源:test_lfw.py
示例2: get_lfw
def get_lfw():
lfw = fetch_lfw_people(resize=1)
lfw.data = lfw.data.astype(np.float32) / 255.0
lfw.target = lfw.target.astype(np.int32)
return lfw.data, lfw.target
开发者ID:ToraxXx,项目名称:gsdr,代码行数:7,代码来源:util.py
示例3: visualize
def visualize():
"""
Writes out various visualizations of our testing data."
"""
print "Preparing visualizations..."
tile_faces(fetch_lfw_people()["images"], constants.LOG_DIR + "/all_faces_tiled.png")
开发者ID:amar37,项目名称:personal-photos-model,代码行数:7,代码来源:visualize.py
示例4: get_eigenfaces
def get_eigenfaces():
# get sklearn faces data set
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=1.0)
n_samples, h, w = lfw_people.images.shape
np.random.seed(42)
# get face data
print "Getting LFW people data from SKLearn..."
X = lfw_people.data
# subtract average row from each row
print "Normalizing image array..."
mean_image = np.mean(X, axis = 0)
arr_norm = np.zeros([n_samples, h*w])
arr_norm = X - mean_image
# run pca using the signular value decomposition
print "Running PCA of input image set. This may take a few moments."
pca = PCA()
pca.fit(arr_norm)
eigenfaces = pca.components_
# Save images
print "Saving eigenfaces..."
path = 'static/eigenface_images/'
for i, face in enumerate(eigenfaces[:50]):
process_image.save_image_vector(path,str(i),face)
print "Complete! Saving pickle files..."
input_data = {'mean_image': mean_image, 'eigenfaces': eigenfaces, 'arr_norm': arr_norm}
f = open('eigenface_data.p', 'wb')
pickle.dump(input_data, f)
f.close()
print "Pickle files saved. Shutting up shop now."
开发者ID:james727,项目名称:Eigenface_Explorer,代码行数:34,代码来源:eigenfaces.py
示例5: dictionary_learn_ex
def dictionary_learn_ex():
patch_shape = (18, 18)
n_atoms = 225
n_plot_atoms = 225
n_nonzero_coefs = 2
n_jobs = 8
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4,color=False)
n_imgs, h, w = lfw_people.images.shape
imgs = []
for i in range(n_imgs):
img = lfw_people.images[i, :, :].reshape((h, w))
img /= 255.
imgs.append(img)
print 'Extracting reference patches...'
X = extract_patches(imgs, patch_size=patch_shape[0],scale=False,n_patches=int(1e5),verbose=True,n_jobs=n_jobs)
print "number of patches:", X.shape[1]
se = sparse_encoder(algorithm='bomp',params={'n_nonzero_coefs': n_nonzero_coefs}, n_jobs=n_jobs)
odc = online_dictionary_coder(n_atoms=n_atoms, sparse_coder=se, n_epochs=2,
batch_size=1000, non_neg=False, verbose=True, n_jobs=n_jobs)
odc.fit(X)
D = odc.D
plt.figure(figsize=(4.2, 4))
for i in range(n_plot_atoms):
plt.subplot(15, 15, i + 1)
plt.imshow(D[:, i].reshape(patch_shape), cmap=plt.cm.gray)
plt.subplots_adjust(left=0.0, bottom=0.0, right=1.0, top=1.0, wspace=0.0, hspace=0.0)
plt.xticks(())
plt.yticks(())
plt.show()
开发者ID:ektormak,项目名称:Lyssandra,代码行数:34,代码来源:visualization_ex.py
示例6: get_lfw
def get_lfw(max_size=None):
dataset = fetch_lfw_people(color=True)
# keep only one image per person
return image_per_label(
dataset.images,
dataset.target,
dataset.target_names,
max_size=max_size)
开发者ID:GunnarEcon,项目名称:fancyimpute,代码行数:8,代码来源:complete_faces.py
示例7: _download_lwf
def _download_lwf(dataset,size):
from sklearn.datasets import fetch_lfw_people
'''
:param dataset:
:return:
'''
lfw_people = fetch_lfw_people(color=True,resize=size)
f = gzip.open(dataset, 'w')
cPkl.dump([lfw_people.images.astype('uint8'),lfw_people.target], f,
protocol=cPkl.HIGHEST_PROTOCOL)
f.close()
开发者ID:casperkaae,项目名称:parmesan,代码行数:11,代码来源:datasets.py
示例8: generateface2picsmapping
def generateface2picsmapping(minimum_faces_per_person=1):
lfw_people = fetch_lfw_people(min_faces_per_person=minimum_faces_per_person, resize=0.4)
n_samples, h, w = lfw_people.images.shape
X, y, target_names = lfw_people.data, lfw_people.target, lfw_people.target_names
n_examples, n_features = X.shape
face2pics = []
print(max(y))
for i in range((max(y)+1)):
face2pics.append([target_names[i],[] ])
for i in range(len(y)):
face2pics[y[i]][1].append(i)
return face2pics
开发者ID:EllenSebastian,项目名称:r-faces,代码行数:12,代码来源:functionsTest.py
示例9: getData2
def getData2():
global X, n, d, y, h, w
lfw_people = fetch_lfw_people(min_faces_per_person=40, resize=0.4)
n, h, w = lfw_people.images.shape
X = lfw_people.data
d = X.shape[1]
y = lfw_people.target
n_classes = lfw_people.target_names.shape[0]
print("Total dataset size:")
print("n_samples: %d" % n)
print("n_features: %d" % d)
print("n_classes: %d" % n_classes)
return X, y, n_classes
开发者ID:brando90,项目名称:6.036_project_2,代码行数:13,代码来源:project2.py
示例10: getFaceData
def getFaceData():
# Download the data, if not already on disk and load it as numpy arrays
lfw_people = fetch_lfw_people(data_home='.', min_faces_per_person=70, resize=0.4)
# insert code here
X = lfw_people.data
n_features = X.shape[1]
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]
n_samples, h, w = lfw_people.images.shape
print "Total dataset size:"
print "n_samples: %d" % n_samples
print "n_features: %d" % n_features
print "n_classes: %d" % n_classes
return X,y,n_features,target_names,n_classes,n_samples,h,w
开发者ID:derZukunft,项目名称:GADataScience2013,代码行数:15,代码来源:pca.py
示例11: get_data
def get_data(dataset_name):
print("Getting dataset: %s" % dataset_name)
if dataset_name == 'lfw_people':
X = fetch_lfw_people().data
elif dataset_name == '20newsgroups':
X = fetch_20newsgroups_vectorized().data[:, :100000]
elif dataset_name == 'olivetti_faces':
X = fetch_olivetti_faces().data
elif dataset_name == 'rcv1':
X = fetch_rcv1().data
elif dataset_name == 'CIFAR':
if handle_missing_dataset(CIFAR_FOLDER) == "skip":
return
X1 = [unpickle("%sdata_batch_%d" % (CIFAR_FOLDER, i + 1))
for i in range(5)]
X = np.vstack(X1)
del X1
elif dataset_name == 'SVHN':
if handle_missing_dataset(SVHN_FOLDER) == 0:
return
X1 = sp.io.loadmat("%strain_32x32.mat" % SVHN_FOLDER)['X']
X2 = [X1[:, :, :, i].reshape(32 * 32 * 3) for i in range(X1.shape[3])]
X = np.vstack(X2)
del X1
del X2
elif dataset_name == 'low rank matrix':
X = make_low_rank_matrix(n_samples=500, n_features=np.int(1e4),
effective_rank=100, tail_strength=.5,
random_state=random_state)
elif dataset_name == 'uncorrelated matrix':
X, _ = make_sparse_uncorrelated(n_samples=500, n_features=10000,
random_state=random_state)
elif dataset_name == 'big sparse matrix':
sparsity = np.int(1e6)
size = np.int(1e6)
small_size = np.int(1e4)
data = np.random.normal(0, 1, np.int(sparsity/10))
data = np.repeat(data, 10)
row = np.random.uniform(0, small_size, sparsity)
col = np.random.uniform(0, small_size, sparsity)
X = sp.sparse.csr_matrix((data, (row, col)), shape=(size, small_size))
del data
del row
del col
else:
X = fetch_mldata(dataset_name).data
return X
开发者ID:0664j35t3r,项目名称:scikit-learn,代码行数:48,代码来源:bench_plot_randomized_svd.py
示例12: gen_face_sets
def gen_face_sets():
people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
n_samples, h, w = people.images.shape
data = people.data
n_features = data.shape[1]
target = people.target
target_names = people.target_names
n_classes = target_names.shape[0]
N = len(target)
inds = random.sample(sp.arange(0, N), N)
n_train = int(sp.floor(0.8 * N))
trainingdata = data[inds[0:n_train], :]
trainingtarget = target[inds[0:n_train]]
testdata = data[inds[n_train:]]
testtarget = target[inds[n_train:]]
return trainingdata, testdata, trainingtarget, testtarget
开发者ID:rachelwebb,项目名称:numerical_computing,代码行数:19,代码来源:imagerecognition.py
示例13: load_data
def load_data():
global training_data, testing_data
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
xs = lfw_people.data
ys = lfw_people.target
inputs = []
labels = list(ys)
for face in xs:
V = Vol(50, 37, 1, 0.0)
V.w = list(face)
inputs.append(augment(V, 30))
x_tr, x_te, y_tr, y_te = train_test_split(inputs, labels, test_size=0.25)
training_data = zip(x_tr, y_tr)
testing_data = zip(x_te, y_te)
print 'Dataset made...'
开发者ID:Aaronduino,项目名称:ConvNetPy,代码行数:22,代码来源:faces.py
示例14: fetch_lfw_people
# coding:utf-8
import logging
from time import time
from sklearn.datasets import fetch_lfw_people
from sklearn.cross_validation import train_test_split
from sklearn.decomposition import RandomizedPCA
from sklearn.grid_search import GridSearchCV
from sklearn.svm import SVC
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s")
lfw_people = fetch_lfw_people(data_home="D:\\My documents\\code\\dataset\\", resize=0.4)
n_samples, h, w = lfw_people.images.shape
X = lfw_people.data
n_features = X.shape[1]
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]
print ("Total dataset size:")
print ("n_samples: %d" % n_samples)
print ("n_features: %d" % n_features)
print ("n_classes: %d" % n_classes)
开发者ID:guker,项目名称:algrithm-learn,代码行数:30,代码来源:facedetect.py
示例15: test_load_fake_lfw_people_too_restrictive
def test_load_fake_lfw_people_too_restrictive():
fetch_lfw_people(data_home=SCIKIT_LEARN_DATA, min_faces_per_person=100, download_if_missing=False)
开发者ID:Claire-Ling-Liu,项目名称:scikit-learn,代码行数:2,代码来源:test_lfw.py
示例16: test_load_empty_lfw_people
def test_load_empty_lfw_people():
fetch_lfw_people(data_home=SCIKIT_LEARN_EMPTY_DATA, download_if_missing=False)
开发者ID:Claire-Ling-Liu,项目名称:scikit-learn,代码行数:2,代码来源:test_lfw.py
示例17: nudge_dataset
data = numpy.asarray(digits.data, dtype='float32')
target = numpy.asarray(digits.target, dtype='int32')
nudged_x, nudged_y = nudge_dataset(data, target)
if SCALE:
nudged_x = preprocessing.scale(nudged_x)
x_train, x_test, y_train, y_test = cross_validation.train_test_split(
nudged_x, nudged_y, test_size=0.2, random_state=42)
train_models(x_train, y_train, x_test, y_test, nudged_x.shape[1],
len(set(target)), numpy_rng=numpy.random.RandomState(123),
name='digits')
if FACES:
import logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(message)s')
lfw_people = datasets.fetch_lfw_people(min_faces_per_person=50,
resize=0.4)
X = numpy.asarray(lfw_people.data, dtype='float32')
if SCALE:
X = preprocessing.scale(X)
y = numpy.asarray(lfw_people.target, dtype='int32')
target_names = lfw_people.target_names
print("Total dataset size:")
print("n samples: %d" % X.shape[0])
print("n features: %d" % X.shape[1])
print("n classes: %d" % target_names.shape[0])
x_train, x_test, y_train, y_test = cross_validation.train_test_split(
X, y, test_size=0.2, random_state=42)
train_models(x_train, y_train, x_test, y_test, X.shape[1],
len(set(y)), numpy_rng=numpy.random.RandomState(123),
name='faces')
开发者ID:goelrhea1992,项目名称:AdaptiveLearning,代码行数:32,代码来源:AdaptiveLearningDNN.py
示例18: lfwTest01
def lfwTest01():
from sklearn.datasets import fetch_lfw_people
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
for name in lfw_people.target_names:
print(name)
开发者ID:hyliu0302,项目名称:scikit-learn-notes,代码行数:6,代码来源:myScikitLearnFcns.py
示例19: main
def main():
print(__doc__)
# Display progress logs on stdout
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
###############################################################################
# Download the data, if not already on disk and load it as numpy arrays
lfw_people = fetch_lfw_people(min_faces_per_person=100, resize=0.4)
# introspect the images arrays to find the shapes (for plotting)
n_samples, h, w = lfw_people.images.shape
# for machine learning we use the 2 data directly (as relative pixel
# positions info is ignored by this model)
X = lfw_people.data
n_features = X.shape[1]
# the label to predict is the id of the person
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]
print("Total dataset size:")
print("n_samples: %d" % n_samples)
print("n_features: %d" % n_features)
print("n_classes: %d" % n_classes)
###############################################################################
# Split into a training set and a test set using a stratified k fold
# split into a training and testing set
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25)
n_train_samples = X_train.shape[0]
n_test_samples = X_test.shape[0]
###############################################################################
# legacy PCA: just computes all the eigenvectors of the training data
# then select eigenvectors that have the highest eigenvalues
legacy_PCA_demo = False
if legacy_PCA_demo:
n_components = 150
print("Extracting the top %d eigenfaces from %d faces using legacy PCA"
% (n_components, X_train.shape[0]))
t0 = time()
pca = LegacyPCA(n_components=n_components, whiten=True).fit(X_train)
print("done in %0.3fs" % (time() - t0))
print("Projecting the input data on the eigenfaces orthonormal basis")
t0 = time()
X_train_pca_legacy = pca.transform(X_train)
X_test_pca_legacy = pca.transform(X_test)
print("done in %0.3fs" % (time() - t0))
print("Fitting the Prototype classifier to the training set using legacy PCA")
t0 = time()
clf = PrototypeClassifier().fit(X_train_pca_legacy, y_train)
print("done in %0.3fs" % (time() - t0))
print("Predicting people's names on the test set")
t0 = time()
y_pred = clf.predict(X_test_pca_legacy)
print("done in %0.3fs" % (time() - t0))
print(classification_report(y_test, y_pred, target_names=target_names))
print("Fitting the SVM classifier to the training set using legacy PCA")
t0 = time()
param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5],
'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1], }
clf = GridSearchCV(SVC(kernel='rbf', class_weight='auto'), param_grid)
clf = clf.fit(X_train_pca_legacy, y_train)
print("done in %0.3fs" % (time() - t0))
print("Best estimator found by grid search:")
print(clf.best_estimator_)
print("Predicting people's names on the test set")
t0 = time()
y_pred = clf.predict(X_test_pca_legacy)
print("done in %0.3fs" % (time() - t0))
print(classification_report(y_test, y_pred, target_names=target_names))
##############################################################################
# Random PCA
random_PCA_demo = True
if random_PCA_demo:
n_components = 150
print("Extracting the top %d eigenfaces from %d faces using random PCA"
% (n_components, X_train.shape[0]))
t0 = time()
pca = RandomizedPCA(n_components=n_components, whiten=True).fit(X_train)
#.........这里部分代码省略.........
开发者ID:gongbudaizhe,项目名称:bilib,代码行数:101,代码来源:face_recognition.py
示例20: fetch_lfw_people
from sklearn.cross_validation import train_test_split
from sklearn.datasets import fetch_lfw_people
from sklearn.grid_search import GridSearchCV
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.decomposition import RandomizedPCA
from sklearn.svm import SVC
# Display progress logs on stdout
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
###############################################################################
# Download the data, if not already on disk and load it as numpy arrays
lfw_people = fetch_lfw_people(data_home='.', min_faces_per_person=70, resize=0.4)
# introspect the images arrays to find the shapes (for plotting)
n_samples, h, w = lfw_people.images.shape
# fot machine learning we use the 2 data directly (as relative pixel
# positions info is ignored by this model)
X = lfw_people.data
n_features = X.shape[1]
# the label to predict is the id of the person
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]
print "Total dataset size:"
开发者ID:kevinbluer,项目名称:data-science,代码行数:31,代码来源:face_recognition.py
注:本文中的sklearn.datasets.fetch_lfw_people函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论