在sklearn上读取人脸数据集保存图片到本地

程序如下:

# -*- coding: utf-8 -*-
"""
Created on Sat Oct 31 17:36:56 2015

"""
import logging
from time import time

from numpy.random import RandomState
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from sklearn.datasets import fetch_olivetti_faces
# Load faces data 读取数据集
dataset = fetch_olivetti_faces(shuffle=True, random_state=rng)

faces = dataset.data
# 读取行列数
row,col = np.shape(faces)
for i in range(row):
    facename = 'face/face'+str(i)+'.jpg'
    # 保存图片
    mpimg.imsave(facename,faces[i,:].reshape(64,64),cmap=plt.cm.gray)
原文地址:https://www.cnblogs.com/theskulls/p/4927313.html