w2 = np.load('w2')
        w3 = np.load('w3')
        w4 = np.load('w4')

        b1 = np.load('b1')
        b2 = np.load('b2')
        b3 = np.load('b3')
        b4 = np.load('b4')
    else:
        w1, b1 = init_weights(784, 256)
        w2, b2 = init_weights(256, 256)
        w3, b3 = init_weights(256, 256)
        w4, b4 = init_weights(256, 10)

    t = time.time()
    w1, w2, w3, w4, b1, b2, b3, b4, losses = minibatch_gd(
        30, w1, w2, w3, w4, b1, b2, b3, b4, x_train, y_train, 10)
    print("runtime: ", time.time() - t)

    np.save('w1', w1)
    np.save('w2', w2)
    np.save('w3', w3)
    np.save('w4', w4)

    np.save('b1', b1)
    np.save('b2', b2)
    np.save('b3', b3)
    np.save('b4', b4)

    avg_class_rate, class_rate_per_class, y_pred = test_nn(
        w1, w2, w3, w4, b1, b2, b3, b4, x_test, y_test, 10)
示例#2
0
        w3 = np.load('w3')
        w4 = np.load('w4')

        b1 = np.load('b1')
        b2 = np.load('b2')
        b3 = np.load('b3')
        b4 = np.load('b4')
    else:
        w1, b1 = init_weights(784, 256)
        w2, b2 = init_weights(256, 256)
        w3, b3 = init_weights(256, 256)
        w4, b4 = init_weights(256, 10)

    num_epochs = 50
    start_time = time.time()
    w1, w2, w3, w4, b1, b2, b3, b4, losses = minibatch_gd(num_epochs, w1, w2, w3, w4, b1, b2, b3, b4, x_train, y_train, 10)
    end_time = time.time()
    np.save('w1', w1)
    np.save('w2', w2)
    np.save('w3', w3)
    np.save('w4', w4)

    np.save('b1', b1)
    np.save('b2', b2)
    np.save('b3', b3)
    np.save('b4', b4)

    plt.plot(np.arange(num_epochs), losses)
    plt.xlabel("Epochs")
    plt.ylabel("Losses")