def convert_images():

    # convert the training data
    for i in range(4):

        # Open up the file to write in
        path = "./test_data/" + cfg.emojis[i] + "/converted.csv"
        f = open(path, 'w+')
        w = csv.writer(f)

        # Get the test cases
        test_cases = glob.glob('./test_data/' + cfg.emojis[i] + '/*.png')
        print 'Converting ' + cfg.emojis[i]

        for test_case in test_cases:
            # convert image
            data = image.binary_image(test_case, cfg.RES)
            data = image.convert_to_1d(data)

            # Write data into file
            w.writerow(data)

        # close the file
        f.close()

    print("files converted!")
Exemple #2
0
def get_testing_error(net):

    # choose an emotion:
    error = [0.0, 0.0, 0.0, 0.0]
    for i, emotion in enumerate(cfg.emojis):
        test_cases = glob.glob('./test_data/non-training/' + emotion + '/*.png')
        for test_case in test_cases:
            inp = image.convert_to_1d(image.binary_image(test_case, cfg.RES))
            e = net.forward_pass(inp)
            error[i] += nn.error(cfg.outputs[i], e)
        error[i] /= len(test_cases)
    return sum(error)
Exemple #3
0
def test_image(path, net):

    # Run the image
    inp = image.convert_to_1d(image.binary_image(path, cfg.RES))
    result = net.forward_pass(inp)
    normalize(result)

    # print out result
    print(path + ":")
    print("     heart eyes:" + str(format((result[0]*100), '.2f')) + "%")
    print("     laugh:" + str(format((result[1]*100), '.2f')) + "%")
    print("     sad:" + str(format((result[2]*100), '.2f')) + "%")
    print("     smile:" + str(format((result[3]*100), '.2f')) + "%")