@@ -0,0 +1,1950 @@
+import numpy as np%0D%0Aimport tensorflow as tf%0D%0A%0D%0Aimage_size = 48   #width = height%0D%0Acol_channels = 3 %09#RGB%0D%0A%0D%0A%0D%0Adef initVariable(name, shape):%0D%0A%09%22%22%22%0D%0A    Initialize weights and biases based on http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf%0D%0A    %22%22%22%0D%0A%09return tf.get_variable(name, shape, initializer=tf.contrib.layers.xavier_initializer())%0D%0A%0D%0Adef conv2d(x, W):%0D%0A%09%22%22%22%0D%0A    Basic convolution. %0D%0A    %22%22%22%0D%0A%09return tf.nn.conv2d(x, W, strides=%5B1, 1, 1, 1%5D, padding='SAME')%0D%0A%0D%0Adef max_pool_2x2(x):%0D%0A%09%22%22%22%0D%0A    Basic pooling%0D%0A    %22%22%22%0D%0A%09return tf.nn.max_pool(x, ksize=%5B1, 2, 2, 1%5D,%0D%0A                        strides=%5B1, 2, 2, 1%5D, padding='SAME')%0D%0A%09%09%09%09%09%09%0D%0A%0D%0A%09%09%09%09%09%09%0D%0A#Note:  tf.name_scope is used for structuring the graph%0D%0A#Note: learningrate should be around 1e-4....1e-6%0D%0A#Note: Minimum viable model%0D%0Awith tf.name_scope('Network'):%0D%0A%0D%0A%09with tf.name_scope('input'):%0D%0A%09%09x_image = tf.placeholder(tf.float32, %5BNone, image_size, image_size, col_channels%5D, name='Images_raw')%0D%0A%09%09y_raw = tf.placeholder(tf.int32, %5BNone%5D ,name='Labels_raw')%0D%0A%09%09y_= tf.one_hot(indices=y_raw, depth=43 ,  name='Labels_oneHot')%0D%0A%09%09%0D%0A%09with tf.name_scope('learningrate'):%0D%0A%09%09learningrate = tf.placeholder(tf.float32)%0D%0A%0D%0A%09with tf.name_scope('OutputLayer'):%0D%0A%09%09x_image_flat = tf.reshape(x_image, %5B-1, image_size * image_size *col_channels%5D)%0D%0A%09%09W_out = initVariable(%22Wout%22,%5Bimage_size * image_size *col_channels, 43%5D)%0D%0A%09%09b_out = initVariable(%22Bout%22, %5B43%5D)%0D%0A%0D%0A%09with tf.name_scope(%22softmax%22):%0D%0A%09%09y_conv=tf.nn.softmax(tf.matmul(x_image_flat, W_out) + b_out)%0D%0A%0D%0A%09with tf.name_scope('cross_entropy'):%0D%0A%09%09cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y_conv))%0D%0A%0D%0A%09with tf.name_scope('train'):%0D%0A%09%09train_step = tf.train.AdamOptimizer(learningrate).minimize(cross_entropy)%0D%0A%0D%0A%0D%0A%09with tf.name_scope('Accuracy'):%0D%0A%09%09correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))%0D%0A%09%09accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float64))%0D%0A

Add files via upload