Linear(10, act='linear', keep_prob=dropout),
        Softmax()
    ])

    x = tf.placeholder(tf.float32, [batch_size, 784], name='x-input')
    y_labels = tf.placeholder(tf.float32, [batch_size, 10], name='y-input')

    y_pred = net.forward(x)

    correct_prediction = tf.equal(tf.argmax(y_labels, axis=1),
                                  tf.argmax(y_pred, axis=1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

    trainer = net.fit(output=y_pred,
                      ground_truth=y_labels,
                      loss='softmax_crossentropy',
                      optimizer='adagrad',
                      opt_params=[learning_rate]).train

    tf.global_variables_initializer().run()

    for i in range(training_iterations):
        feed_d = feed_dict(mnist, True)
        d = {x: feed_d[0], y_labels: feed_d[1]}
        _, pred, acc = sess.run([trainer, y_pred, accuracy], feed_dict=d)
        if i % 200 == 0:
            # TODO prune network
            feed_d = feed_dict(mnist, False)
            d = {x: feed_d[0], y_labels: feed_d[1]}
            acc = sess.run(accuracy, feed_dict=d)
            print(acc)
Esempio n. 2
0
def main():
    global EPOCHS, BATCH_SIZE, LEARNING_RATE
    # train_X, test_X, train_y, test_y = get_iris_data()

    # Saver
    name = ""

    print("Train? (y for train, n for test)")
    choice = input()
    train_flag = True
    if (choice =='n' or choice=='N'):
        df = pd.read_csv("data/out-test.csv")
        BATCH_SIZE = df.shape[0]
        EPOCHS = 1
        train_flag = False
        name = input("Enter model file name: ")
    else:
         df = pd.read_csv("data/out-train.csv")



    cols = df.columns.values
    cols = np.delete(cols, [1])
    train_X = df.loc[:,cols].values

    train_y = df["decile_score"].values
    y_train_ = train_y
    train_y = keras.utils.np_utils.to_categorical(train_y)



    print(train_X.shape)
    print(train_y.shape)
    # exit()
    # Layer's sizes
    x_size = train_X.shape[1]   # Number of input nodes: 4 features and 1 bias
    # h_size_1 = 256                                # Number of hidden nodes
    # h_size_2 = 256                                # Number of hidden nodes
    # h_size_3 = 128                                # Number of hidden nodes
    # h_size_4 = 64                                  # Number of hidden nodes
    # h_size_5 = 64                                  # Number of hidden nodes
    # h_size_6 = 32                                  # Number of hidden nodes
    # h_size_7 = 16                                  # Number of hidden nodes
    # h_size_8 = 8                                  # Number of hidden nodes
    y_size = train_y.shape[1]   # Number of outcomes (3 iris flowers)

    # Symbols
    X = tf.placeholder("float", shape=[None, x_size])
    y = tf.placeholder("float", shape=[None, y_size])

    net = Sequential([Linear(input_dim=166, output_dim=256, act ='relu', batch_size=BATCH_SIZE),
                 Linear(256, act ='relu'), 
                 Linear(128, act ='relu'), 
                 Linear(64, act ='relu'), 
                 Linear(64, act ='relu'), 
                 Linear(32, act ='relu'), 
                 Linear(16, act ='relu'),
                 Linear(8, act ='relu'),
                 Linear(3, act ='relu'),
                 Softmax()])

    output = net.forward(tf.convert_to_tensor(X))

    trainer = net.fit(output, y, loss='softmax_crossentropy', optimizer='adam', opt_params=[LEARNING_RATE])