Skip to content

Instantly share code, notes, and snippets.

@mick001
Last active March 13, 2019 08:16
Show Gist options
  • Save mick001/0782247969b1fa25795b09574d7ecf0a to your computer and use it in GitHub Desktop.
Save mick001/0782247969b1fa25795b09574d7ecf0a to your computer and use it in GitHub Desktop.
Image recognition tutorial in R using deep convolutional neural networks (MXNet package). Part 1. Full article at https://firsttimeprogrammer.blogspot.com/2016/08/image-recognition-tutorial-in-r-using.html
# -*- coding: utf-8 -*-
# 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!
@ybbaipku
Copy link

Thanks for sharing the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment