Skip to content

Instantly share code, notes, and snippets.

@billhhh
Forked from mick001/download_olivetty_faces.py
Created November 10, 2019 00:03
Show Gist options
  • Save billhhh/086e948fdb1e0e29b3bf4a8ac79397b7 to your computer and use it in GitHub Desktop.
Save billhhh/086e948fdb1e0e29b3bf4a8ac79397b7 to your computer and use it in GitHub Desktop.
Download Olivetti faces dataset in Python
# Imports
from sklearn.datasets import fetch_olivetti_faces
import numpy as np
# Download Olivetti faces dataset
olivetti = fetch_olivetti_faces()
x = olivetti.images
y = olivetti.target
# Print info on shapes and reshape where necessary
print("Original x shape:", x.shape)
X = x.reshape((400, 4096))
print("New x shape:", X.shape)
print("y shape", y.shape)
# Save the numpy arrays
np.savetxt("C://olivetti_X.csv", X, delimiter = ",")
np.savetxt("C://olivetti_y.csv", y, delimiter = ",", fmt = '%d')
print("\nDownloading and reshaping done!")
################################################################################
# OUTPUT
################################################################################
#
# Original x shape: (400, 64, 64)
# New x shape: (400, 4096)
# y shape (400,)
#
# Downloading and reshaping done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment