import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np def make2D(vector, size=(101, 101)): print vector.shape return vector.reshape(size).T def save_example_face(vector, fig_outfile): im = make2D(vector) plt.imshow(im, cmap='gray') plt.tight_layout() plt.savefig(fig_outfile, bbox_inches='tight') if __name__ == "__main__": from faces import faces trX, trY, teX, teY = faces(contrast=True) save_example_face(teX[0], 'example_face_contrast.png')
import numpy as np import theano from six.moves import cPickle from theano import tensor as T from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams from sklearn.metrics import accuracy_score from faces import faces, permute from performanceplot import performanceplot import failure_analysis srng = RandomStreams() trX, trY, teX, teY = faces(zscore=False, onehot=False, adjust_targets=True, contrast=True) print trX.shape print trY.shape print teX.shape print teY.shape input_dim = trX.shape[1] mode = raw_input("What should this script do? (train, something else):") def floatX(X): return np.asarray(X, dtype=theano.config.floatX) def init_weights(shape): return theano.shared(floatX(np.random.randn(*shape) * 0.02)) def sgd(cost, params, lr=0.05): grads = T.grad(cost=cost, wrt=params) updates = [] for p, g in zip(params, grads):
import numpy as np from foxhound.models import Network from foxhound import ops from foxhound import iterators from foxhound.transforms import OneHot from foxhound.theano_utils import floatX from sklearn.metrics import accuracy_score from faces import faces binary_output = True trX, trY, teX, teY = faces(zscore=True, adjust_targets=True) def model_perceptron(input_shape): model = [ ops.Input(['x', input_shape]), ops.Project(dim=1), ops.Activation('sigmoid') ] return model def model_MLP(input_shape): model = [ ops.Input(['x', input_shape]), ops.Project(dim=1000), ops.Activation('tanh'),
import numpy as np import theano from theano import tensor as T from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams from sklearn.metrics import accuracy_score from faces import faces, permute from performanceplot import performanceplot srng = RandomStreams() trX, trY, teX, teY = faces(contrast=True, perceptron=True) print "target values (min, max): ", (teY.min(), teY.max()) print trX.shape print trY.shape input_dim = trX.shape[1] def floatX(X): return np.asarray(X, dtype=theano.config.floatX) def init_weights(shape): return theano.shared(floatX(np.random.randn(*shape) * 0.02)) def model(X, w_o): return T.sgn(T.dot(X, w_o)) X = T.fmatrix() Y = T.fmatrix()
import numpy as np import theano from theano import tensor as T from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams from sklearn.metrics import accuracy_score from faces import faces, permute from performanceplot import performanceplot srng = RandomStreams() trX, trY, teX, teY = faces(contrast=True, perceptron=True) print "target values (min, max): ", (teY.min(), teY.max()) print trX.shape print trY.shape input_dim = trX.shape[1] def floatX(X): return np.asarray(X, dtype=theano.config.floatX) def init_weights(shape): return theano.shared(floatX(np.random.randn(*shape) * 0.02)) def model(X, w_o): return T.sgn(T.dot(X, w_o)) X = T.fmatrix() Y = T.fmatrix() # theano.config.compute_test_value = 'warn' # Use 'warn' to activate this featureg # X.tag.test_value = np.zeros((1, input_dim), dtype='float32')
import numpy as np import theano from six.moves import cPickle from theano import tensor as T from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams from sklearn.metrics import accuracy_score from faces import faces, permute from performanceplot import performanceplot import failure_analysis srng = RandomStreams() trX, trY, teX, teY = faces(zscore=False, onehot=False, adjust_targets=True, contrast=True) print trX.shape print trY.shape print teX.shape print teY.shape input_dim = trX.shape[1] mode = raw_input("What should this script do? (train, something else):") def floatX(X): return np.asarray(X, dtype=theano.config.floatX) def init_weights(shape): return theano.shared(floatX(np.random.randn(*shape) * 0.02))
import numpy as np from foxhound.models import Network from foxhound import ops from foxhound import iterators from foxhound.transforms import OneHot from foxhound.theano_utils import floatX from sklearn.metrics import accuracy_score from faces import faces binary_output = True trX, trY, teX, teY = faces(zscore=True, adjust_targets=True) def model_perceptron(input_shape): model = [ops.Input(["x", input_shape]), ops.Project(dim=1), ops.Activation("sigmoid")] return model def model_MLP(input_shape): model = [ ops.Input(["x", input_shape]), ops.Project(dim=1000), ops.Activation("tanh"), ops.Project(dim=500), ops.Activation("tanh"), ops.Project(dim=75), ops.Activation("tanh"),