def nn(): return Sequential([ Convolution(output_depth=FLAGS.output_dim, input_depth=1, batch_size=FLAGS.batch_size, input_dim=FLAGS.image_dim, act='relu', stride_size=1, pad='VALID'), AvgPool(), Convolution(output_depth=25, stride_size=1, act='relu', pad='VALID'), AvgPool(), Convolution(output_depth=25, stride_size=1, act='relu', pad='VALID'), AvgPool(), Convolution(kernel_size=4, output_depth=100, stride_size=1, act='relu', pad='VALID'), AvgPool(), Convolution(kernel_size=1, output_depth=FLAGS.output_dim, stride_size=1, pad='VALID'), Softmax() ])
def nn(): return Sequential([ Linear(input_dim=784, output_dim=1296, act='relu', batch_size=FLAGS.batch_size), Linear(1296, act='relu'), Linear(1296, act='relu'), Linear(10, act='relu'), Softmax() ])
def layers(x): # Define the layers of your network here return Sequential([ Linear(input_dim=784, output_dim=1296, act='relu', batch_size=FLAGS.batch_size), Linear(1296, act='relu'), Linear(1296, act='relu'), Linear(10), Softmax() ])
def nn(): return Sequential([ Linear(input_dim=166, output_dim=256, act='relu', batch_size=FLAGS.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() ])
mnist = input_data.read_data_sets('data', one_hot=True) with tf.Session() as sess: # GRAPH net = Sequential([ Linear(input_dim=784, output_dim=1200, act='relu', batch_size=batch_size, keep_prob=dropout), Linear(500, act='relu', keep_prob=dropout), 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',
def nn(phase): net = Sequential([ Convolution(kernel_size=3, output_depth=64, input_depth=3, batch_size=32, input_dim=3, act='relu', stride_size=1, pad='SAME', batch_norm=True, phase=phase), Convolution(kernel_size=3, output_depth=64, input_depth=64, batch_size=32, act='relu', stride_size=1, pad='SAME', batch_norm=True, phase=phase), MaxPool(), Convolution(kernel_size=3, output_depth=128, input_depth=64, batch_size=32, act='relu', stride_size=1, pad='SAME', batch_norm=True, phase=phase), Convolution(kernel_size=3, output_depth=128, input_depth=128, batch_size=32, act='relu', stride_size=1, pad='SAME', batch_norm=True, phase=phase), MaxPool(), Convolution(kernel_size=3, output_depth=256, input_depth=128, batch_size=32, act='relu', stride_size=1, pad='SAME', batch_norm=True, phase=phase), Convolution(kernel_size=3, output_depth=256, input_depth=256, batch_size=32, act='relu', stride_size=1, pad='SAME', batch_norm=True, phase=phase), Convolution(kernel_size=3, output_depth=256, input_depth=256, batch_size=32, act='relu', stride_size=1, pad='SAME', batch_norm=True, phase=phase), MaxPool(), Convolution(kernel_size=4, output_depth=512, stride_size=1, act='relu', pad='VALID', batch_norm=True, phase=phase), Convolution(kernel_size=1, output_depth=512, stride_size=1, act='relu', pad='VALID', batch_norm=True, phase=phase), Convolution(kernel_size=1, output_depth=10, stride_size=1, act='linear', pad='VALID', batch_norm=True, phase=phase), Softmax(), ]) return net
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])