def renderResults200(name, results, test_x, activations_0, activations_1):

    image = Image.new('RGB', (28 * 3 + 800, len(results) * 180))
    draw = ImageDraw.Draw(image)

    for index, result in enumerate(results):

        renderDigit(draw, test_x[index][0], 0 * 28, index * 180 + 0 * 36)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[0][10:])) + ".png",
                    2 * 28, index * 180 + 0 * 36)
        renderActivations200(draw, activations_0[index][0], 3 * 28,
                             index * 180 + 0 * 36)
        renderActivations200(draw, activations_1[index][0], 3 * 28,
                             index * 180 + 0 * 36 + 16)

        renderDigit(draw, test_x[index][1], 0 * 28, index * 180 + 1 * 36)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[1][10:])) + ".png",
                    2 * 28, index * 180 + 1 * 36)
        renderActivations200(draw, activations_0[index][1], 3 * 28,
                             index * 180 + 1 * 36)
        renderActivations200(draw, activations_1[index][1], 3 * 28,
                             index * 180 + 1 * 36 + 16)

        renderDigit(draw, test_x[index][2], 0 * 28, index * 180 + 2 * 36)
        renderImage(image, "MNIST_data/" + getOperator(result[2][:4]) + ".png",
                    2 * 28, index * 180 + 2 * 36)
        renderActivations200(draw, activations_0[index][2], 3 * 28,
                             index * 180 + 2 * 36)
        renderActivations200(draw, activations_1[index][2], 3 * 28,
                             index * 180 + 2 * 36 + 16)

        renderDigit(draw, test_x[index][3], 0 * 28, index * 180 + 3 * 36)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[3][:10])) + ".png",
                    1 * 28, index * 180 + 3 * 36)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[3][10:20])) + ".png",
                    2 * 28, index * 180 + 3 * 36)
        renderActivations200(draw, activations_0[index][3], 3 * 28,
                             index * 180 + 3 * 36)
        renderActivations200(draw, activations_1[index][3], 3 * 28,
                             index * 180 + 3 * 36 + 16)

    image.save(name + ".png")
def renderResults(name, results, test_x, activations_0, activations_1):

    image = Image.new('RGB', (28 * 3 + 280, len(results) * 160))
    draw = ImageDraw.Draw(image)

    for index, result in enumerate(results):

        renderImage(image,
                    "MNIST_data/" + str(argmax(test_x[index][0])) + ".png",
                    0 * 28, index * 160 + 0 * 32)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[0][10:])) + ".png",
                    2 * 28, index * 160 + 0 * 32)
        renderActivations(draw, activations_1[index][0], 3 * 28,
                          index * 160 + 0 * 32)
        renderActivations(draw, activations_0[index][0], 3 * 28,
                          index * 160 + 0 * 32 + 14)

        renderImage(image,
                    "MNIST_data/" + str(argmax(test_x[index][1])) + ".png",
                    0 * 28, index * 160 + 1 * 32)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[1][10:])) + ".png",
                    2 * 28, index * 160 + 1 * 32)
        renderActivations(draw, activations_1[index][1], 3 * 28,
                          index * 160 + 1 * 32)
        renderActivations(draw, activations_0[index][1], 3 * 28,
                          index * 160 + 1 * 32 + 14)

        renderImage(image,
                    "MNIST_data/" + getOperator(test_x[index][2][:4]) + ".png",
                    0 * 28, index * 160 + 2 * 32)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[2][:10])) + ".png",
                    1 * 28, index * 160 + 2 * 32)
        renderImage(image,
                    "MNIST_data/" + str(argmax(result[2][10:20])) + ".png",
                    2 * 28, index * 160 + 2 * 32)
        renderActivations(draw, activations_1[index][2], 3 * 28,
                          index * 160 + 2 * 32)
        renderActivations(draw, activations_0[index][2], 3 * 28,
                          index * 160 + 2 * 32 + 14)

    image.save(name + ".png")
Example #3
0
def renderResults(name, results, test_y):

    image = Image.new('RGB', (28 * 14, 28 * len(results)))
    draw = ImageDraw.Draw(image)

    with open(name + ".txt", "w") as f:

        for index, result in enumerate(results):

            strIndex = "{:03}".format(index)

            f.write(strIndex + ": " + str(argmax(test_y[index][3][10:20])) +
                    " " + getOperatorSign(test_y[index][3][20:30]) + " " +
                    str(argmax(test_y[index][3][:10])) + "\r\n")
            f.write("\t" + str(argmax(result[0][:10])) + " " +
                    str(argmax(result[0][10:20])) + " " +
                    getOperatorSign(result[0][20:30]) + " " +
                    str(argmax(result[0][-20:-10])) + " " +
                    str(argmax(result[0][-10:])) + "\r\n")
            f.write("\t" + str(argmax(result[1][:10])) + " " +
                    str(argmax(result[1][10:20])) + " " +
                    getOperatorSign(result[1][20:30]) + " " +
                    str(argmax(result[1][-20:-10])) + " " +
                    str(argmax(result[1][-10:])) + "\r\n")
            f.write("\t" + str(argmax(result[2][:10])) + " " +
                    str(argmax(result[2][10:20])) + " " +
                    getOperatorSign(result[2][20:30]) + " " +
                    str(argmax(result[2][-20:-10])) + " " +
                    str(argmax(result[2][-10:])) + "\r\n")
            f.write("\t" + str(argmax(result[3][:10])) + " " +
                    str(argmax(result[0][10:20])) + " " +
                    getOperatorSign(result[3][20:30]) + " " +
                    str(argmax(result[3][-20:-10])) + " " +
                    str(argmax(result[3][-10:])) + "\r\n")

            renderImage(image, "MNIST_data/" + strIndex[:1] + ".png", 0 * 28,
                        index * 28)
            renderImage(image, "MNIST_data/" + strIndex[1:2] + ".png", 1 * 28,
                        index * 28)
            renderImage(image, "MNIST_data/" + strIndex[2:] + ".png", 2 * 28,
                        index * 28)
            renderImage(image, "MNIST_data/colon.png", 3 * 28, index * 28)
            renderDigit(draw, test_x[index][1], 4 * 28, index * 28)
            renderDigit(draw, test_x[index][2], 5 * 28, index * 28)
            renderDigit(draw, test_x[index][0], 6 * 28, index * 28)
            renderImage(image, "MNIST_data/implies.png", 7 * 28, index * 28)
            renderImage(image,
                        "MNIST_data/" + str(argmax(result[3][10:20])) + ".png",
                        8 * 28, index * 28)
            renderImage(image,
                        "MNIST_data/" + getOperator(result[3][20:24]) + ".png",
                        9 * 28, index * 28)
            renderImage(image,
                        "MNIST_data/" + str(argmax(result[3][:10])) + ".png",
                        10 * 28, index * 28)
            renderImage(image, "MNIST_data/equals.png", 11 * 28, index * 28)
            renderImage(
                image,
                "MNIST_data/" + str(argmax(result[3][-20:-10])) + ".png",
                12 * 28, index * 28)
            renderImage(image,
                        "MNIST_data/" + str(argmax(result[3][-10:])) + ".png",
                        13 * 28, index * 28)

        image.save(name + ".png")
Example #4
0
    for index, result in enumerate(results):
        left = argmax(result[3][-20:-10])
        right = argmax(result[3][-10:])
        leftTarget = argmax(test_y[index][3][-20:-10])
        rightTarget = argmax(test_y[index][3][-10:])

        if left == leftTarget and right == rightTarget:
            count += 1
        total += 1

        renderDigit(draw, test_x[index][1], 0 * 28, index * 28)
        renderDigit(draw, test_x[index][2], 1 * 28, index * 28)
        renderDigit(draw, test_x[index][0], 2 * 28, index * 28)
        renderImage(image, "MNIST_data/implies.png", 3 * 28, index * 28)
        renderImage(image, "MNIST_data/" + str(argmax(result[1][-10:])) + ".png", 4 * 28, index * 28)
        renderImage(image, "MNIST_data/" + getOperator(result[2][:4]) + ".png", 5 * 28, index * 28)
        renderImage(image, "MNIST_data/" + str(argmax(result[0][-10:])) + ".png", 6 * 28, index * 28)
        renderImage(image, "MNIST_data/equals.png", 7 * 28, index * 28)
        renderImage(image, "MNIST_data/" + str(argmax(result[3][-20:-10])) + ".png", 8 * 28, index * 28)
        renderImage(image, "MNIST_data/" + str(argmax(result[3][-10:])) + ".png", 9 * 28, index * 28)

    image.save("results-without-classes-" + str(k_fold_index) + ".png")
    scores.append(count / float(total))

    k_fold_index += 1

print(scores)

#with-classes:
#[0.8782608695652174, 0.8347826086956521, 0.8869565217391304, 0.8608695652173913, 0.9072463768115943]