From 2a3ac1423a0e0544fcf9b2241c13cfbdba24d0e6 Mon Sep 17 00:00:00 2001 From: MewX Date: Thu, 27 Jul 2017 02:13:37 +0930 Subject: [PATCH] Added tensor flow, wip --- MachineLearning/TensorFlow/test.py | 47 ++++++++++++++++++++++ MachineLearning/TensorFlow/two_buoy_cnn.py | 2 + 2 files changed, 49 insertions(+) create mode 100644 MachineLearning/TensorFlow/test.py create mode 100644 MachineLearning/TensorFlow/two_buoy_cnn.py diff --git a/MachineLearning/TensorFlow/test.py b/MachineLearning/TensorFlow/test.py new file mode 100644 index 0000000..f9dc618 --- /dev/null +++ b/MachineLearning/TensorFlow/test.py @@ -0,0 +1,47 @@ +import tensorflow as tf +from tensorflow.examples.tutorials import mnist + +X = tf.placeholder(tf.float32, [None, 28, 28, 1]) +W = tf.Variable(tf.zeros([784, 10])) +b = tf.Variable(tf.zeros([10])) + +init = tf.initialize_all_variables() + +# model +Y = tf.nn.softmax(tf.matmul(tf.reshape(X, [-1, 784]), W) + b) +Y_ = tf.placeholder(tf.float32, [None, 10]) + +# loss function +cross_entropy = -tf.reduce_sum(Y_ * tf.log*Y) + +### relu +# Yf = tf.nn.relu(tf.matmul(X, W) + b) +# pkeep = tf.placeholder(tf.float32) + +### drop out +# Y = tf.nn.dropout(Yf, pkeep) + +# percentage of correct answers found +is_correct = tf.equal(tf.argmax(Y, 1), tf.argmax(Y_, 1)) +accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32)) + +# train +optimizer = tf.train.GradientDescentOptimizer(0.003) # learning rate +train_step = optimizer.minimiza(cross_entropy) # loss function + + +sess = tf.Session() +sess.run(init) + +for i in range(1000): + # load the batch of images and correct answers + batch_X, batch_Y = mnist.train.next_batch(100) + train_data = {X: batch_X, Y_: batch_Y} + + # train + sess.run(train_step, feed_dict=train_data) + # success + a, c = sess.run([accuracy, cross_entropy], feed_dict=train_data) + # success on testing data? (similar to cross validation) + test_data = {X: mnist.test.images, Y_: mnist.test.labels} + a, c = sess.run([accuracy, cross_entropy], feed=test_data) diff --git a/MachineLearning/TensorFlow/two_buoy_cnn.py b/MachineLearning/TensorFlow/two_buoy_cnn.py new file mode 100644 index 0000000..b187bef --- /dev/null +++ b/MachineLearning/TensorFlow/two_buoy_cnn.py @@ -0,0 +1,2 @@ +import tensorflow as tf +