Skip to content

Instantly share code, notes, and snippets.

@berak
Last active December 18, 2015 09:31
Show Gist options
  • Select an option

  • Save berak/b16f2f82fef7cb280b0c to your computer and use it in GitHub Desktop.

Select an option

Save berak/b16f2f82fef7cb280b0c to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
import tensorflow as tf
def asRow(X):
"""
Creates a row-matrix from multi-dimensional data items in list l.
X [list] List with multi-dimensional data.
"""
if len(X) == 0:
return np.array([])
total = 1
for i in range(0, np.ndim(X[0])):
total = total * X[0].shape[i]
mat = np.empty([0, total], dtype=X[0].dtype)
for row in X:
mat = np.append(mat, row.reshape(1,-1), axis=0) # same as vstack
return np.asmatrix(mat)
def load_att():
img = []
lab = []
for i in range(1,41):
for j in range(1,11):
p = "orl_faces/s" + str(i) + "/" + str(j) + ".pgm"
im = cv2.imread(p,0)
img.append(im)
lab.append(i-1)
return img, lab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment