Beispiel #1
0
def main():
    X, Y = get_facialexpression(balance_ones=True)

    M = 2000
    ann = AnnTheano(M)
    ann.fit(X, Y)
    print "score:", ann.score(X, Y)
def main():
    X, Y = get_facialexpression(balance_ones=True)

    M = 200
    ann = ANN(M)
    ann.fit(X, Y, show_figure=True)
    print ann.score(X, Y)
def main():
    X, Y = get_facialexpression(balance_ones=True)

    X, Y = shuffle(X, Y)
    K = len(np.unique(Y))
    #Split into train and test

    Ntrain = int(0.8 * len(Y))
    Xtrain, Ytrain = X[:Ntrain, :], Y[:Ntrain]
    Xtest, Ytest = X[:Ntrain, :], Y[:Ntrain]

    M = 100

    # create the neural network
    model = MLPClassifier(hidden_layer_sizes=(Ntrain, M),
                          activation='logistic',
                          learning_rate='constant',
                          learning_rate_init=1e-7,
                          verbose=True)

    #train ANN
    model.fit(Xtrain, Ytrain)

    # print the train and test accuracy
    train_accuracy = model.score(Xtrain, Ytrain)
    test_accuracy = model.score(Xtest, Ytest)

    print "train accuracy:", train_accuracy, "test accuracy:", test_accuracy
Beispiel #4
0
def main():

    X, T = get_facialexpression(balance_ones=True)
    # X, T  = np.shuffle(X,T)
    label_map = [
        'Anger', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral'
    ]
    # klass =3  error_rate=0.0
    # klass =4  error_rate=0.0
    # klass =5  error_rate=0.0
    # klass =0
    klass = 4
    N, D = X.shape
    X = np.concatenate(
        (np.ones((N, 1)), X),
        axis=1,
    )
    T = T.astype(np.int32)
    X = X.astype(np.float32)
    #Fix for forecasting on one image
    T = class1detect(T, detect=klass)

    D += 1

    # params
    lr = 5e-7
    max_iteration = 150
    W = np.random.randn(D) / np.sqrt(D)
    cost = []
    error = []
    for i in xrange(max_iteration):
        Y = forward(W, X)
        cost.append(cross_entropy(T, Y))
        error.append(error_rate(T, Y))

        W += lr * X.T.dot(T - Y)

        if i % 5 == 0:
            print "i=%d\tcost=%.3f\terror=%.3f" % (i, cost[-1], error[-1])

    if i % 5 == 0:
        print "i=%d\tcost=%.3f\terror=%.3f" % (i, cost[-1], error[-1])

    print "Final weight:", W
    print T
    print np.round(Y)

    plt.title('logistic regression ' + label_map[klass])
    plt.xlabel('iterations')
    plt.ylabel('cross entropy')
    plt.plot(cost)
    plt.show()

    plt.title('logistic regression ' + label_map[klass])
    plt.xlabel('iterations')
    plt.ylabel('error rate')
    plt.plot(error)
    plt.show()
def main():
    print 'Loading ...'
    X, Y = get_facialexpression(balance_ones=True)

    detect = 1
    print 'detecting class', detect
    Y = class1detect(Y, detect)

    model = LogisticModel()
    model.fit(X, Y, epochs=5000, show_figure=True)
    model.score(X, Y)
def main():
    print 'Loading ...'
    X, Y = get_facialexpression(balance_ones=True)

    label_map = [
        'Anger', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral'
    ]
    print Y.shape
    print Y

    # detect=1
    # print 'detecting class', detect
    # Y = class1detect(Y, detect)

    model = LogisticModelK(label=label_map)
    model.fit(X, Y, epochs=200, show_figure=True)
    model.score(X, Y)
def main():
    label_map = [
        'Anger', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral'
    ]
    X, Y = get_facialexpression(balance_ones=False)

    while True:
        for i in xrange(7):
            x, y = X[Y == i], Y[Y == i]
            N = len(x)
            j = np.random.choice(N)
            plt.imshow(x[j].reshape(48, 48),
                       cmap='gray')  # images have been flattened
            plt.title(label_map[y[j]])
            plt.show()
            prompt = raw_input('Quit? Enter Y:\n')

        if prompt == 'Y':
            break
def main():
	X, Y = get_facialexpression(balance_ones=True)
	
	M = 5000 	
	ann = AnnTensorflow1(M)
	ann.fit(X, Y, learning_rate=10e-7, reg=10e-6, show_fig=True)
def main():
	X, Y =  get_facialexpression(balance_ones=True)

	ann = AnnTheano2([2000, 100, 500])
	ann.fit(X, Y)
	print "score:", ann.score(X,Y)
def main():
    X, Y = get_facialexpression(balance_ones=True)

    ann = AnnTensorflow2([2000, 1000, 500])
    print type(ann)
    ann.fit(X, Y, show_figure=True)
def main():
	X, Y = get_facialexpression(balance_ones=True)
	
	model = LogisticModelSoftmax()
	model.fit(X, Y, show_figure=True)
	print model.score(X, Y)