예제 #1
0
파일: imvis.py 프로젝트: youralien/nus-nn
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')
예제 #2
0
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')
예제 #3
0
파일: c_mlp.py 프로젝트: youralien/nus-nn
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):
예제 #4
0
파일: fox.py 프로젝트: Tony-Idle/nus-nn
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'),
예제 #5
0
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()
예제 #6
0
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')
예제 #7
0
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))
예제 #8
0
파일: fox.py 프로젝트: youralien/nus-nn
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"),