Skip to content

Commit

Permalink
Added tensor flow, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MewX committed Jul 26, 2017
1 parent 40cef92 commit 2a3ac14
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions MachineLearning/TensorFlow/test.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions MachineLearning/TensorFlow/two_buoy_cnn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import tensorflow as tf

0 comments on commit 2a3ac14

Please sign in to comment.