From e6927ad18b4165617c1b8c6caca1495ab94d3431 Mon Sep 17 00:00:00 2001 From: Steven Chau Date: Tue, 8 Aug 2017 15:53:16 +0800 Subject: [PATCH 1/5] Add setup instructions for Ubuntu --- setup/setup_instruction.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/setup/setup_instruction.md b/setup/setup_instruction.md index 1118ac93..b2524130 100644 --- a/setup/setup_instruction.md +++ b/setup/setup_instruction.md @@ -62,6 +62,33 @@ $ virtualenv venv --distribute --system-site-packages ``` ### For Ubuntu +Step 1: set up pip and virtual environment +```bash +$ sudo apt-get install python-pip +$ sudo pip install virtualenv +``` + +Step 2: set up a project directory. You will do all work for this class in this directory +```bash +$ mkdir [my project] +``` + +Step 3: set up virtual environment for the project directory. +```bash +$ cd [my project] +$ virtualenv venv +``` +These commands create a venv subdirectory in your project where everything is installed. + +Step 4: to activate the virtual environment +```bash +$ source venv/bin/activate +``` + +Step 5: install tensorflow and other dependencies +```bash +$ pip install -r setup/requirements +``` ### For Windows From 30907d25533fedba6811c61148b0bf97a131d930 Mon Sep 17 00:00:00 2001 From: Steven Chau Date: Tue, 8 Aug 2017 15:54:09 +0800 Subject: [PATCH 2/5] remove UNICODE character to fix Python runtime error --- examples/02_feed_dict.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/02_feed_dict.py b/examples/02_feed_dict.py index 5ab60c58..0dda8d2a 100644 --- a/examples/02_feed_dict.py +++ b/examples/02_feed_dict.py @@ -19,7 +19,7 @@ c = a + b # short for tf.add(a, b) with tf.Session() as sess: - # print(sess.run(c)) # InvalidArgumentError because a doesn’t have any value + # print(sess.run(c)) # InvalidArgumentError because a doesnt have any value # feed [1, 2, 3] to placeholder a via the dict {a: [1, 2, 3]} # fetch value of c @@ -35,4 +35,4 @@ replace_dict = {a: 15} # Run the session, passing in 'replace_dict' as the value to 'feed_dict' - print(sess.run(b, feed_dict=replace_dict)) # >> 45 \ No newline at end of file + print(sess.run(b, feed_dict=replace_dict)) # >> 45 From ede5169f66c793c13149b15903b223a6601e3891 Mon Sep 17 00:00:00 2001 From: Steven Chau Date: Tue, 8 Aug 2017 15:56:56 +0800 Subject: [PATCH 3/5] Fix SyntaxError: Non-ASCII character '\xe2' in file 02_simple_tf.py on line 19, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details --- examples/02_simple_tf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/02_simple_tf.py b/examples/02_simple_tf.py index 0c7fe716..0e08a5ce 100644 --- a/examples/02_simple_tf.py +++ b/examples/02_simple_tf.py @@ -16,7 +16,7 @@ with tf.Session() as sess: writer = tf.summary.FileWriter('./graphs', sess.graph) print(sess.run(x)) -writer.close() # close the writer when you’re done using it +writer.close() # close the writer when youre done using it a = tf.constant([2, 2], name='a') From 48788c5e3534df6232ed9863ff43233272299866 Mon Sep 17 00:00:00 2001 From: Steven Chau Date: Tue, 8 Aug 2017 16:01:28 +0800 Subject: [PATCH 4/5] Fix NameError: name 'shape' is not defined --- examples/02_simple_tf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/02_simple_tf.py b/examples/02_simple_tf.py index 0e08a5ce..1dbd95f7 100644 --- a/examples/02_simple_tf.py +++ b/examples/02_simple_tf.py @@ -27,6 +27,7 @@ # >> [[0 2] # [4 6]] +shape = [2, 2] tf.zeros(shape, dtype=tf.float32, name=None) #creates a tensor of shape and all elements will be zeros (when ran in session) From 8df2838a2a178f202fe8481a6b75d808010df8a2 Mon Sep 17 00:00:00 2001 From: Steven Chau Date: Tue, 8 Aug 2017 19:08:58 +0800 Subject: [PATCH 5/5] Fix runtime errors --- .gitignore | 5 +++++ examples/03_linear_regression_sol.py | 8 ++++---- examples/03_logistic_regression_mnist_sol.py | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6744f372..eb146f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,10 @@ examples/checkpoints/* examples/chatbot/processed/* examples/chatbot/checkpoints/* examples/chatbot/data_analysis.py +examples/data/* +examples/graphs/* +examples/test/* assignments/chatbot/processed/* + +env/* diff --git a/examples/03_linear_regression_sol.py b/examples/03_linear_regression_sol.py index 6fde7360..9389081a 100644 --- a/examples/03_linear_regression_sol.py +++ b/examples/03_linear_regression_sol.py @@ -35,8 +35,8 @@ Y_predicted = X * w + b # Step 5: use the square error as the loss function -loss = tf.square(Y - Y_predicted, name='loss') -# loss = utils.huber_loss(Y, Y_predicted) +#loss = tf.square(Y - Y_predicted, name='loss') +loss = utils.huber_loss(Y, Y_predicted) # Step 6: using gradient descent with learning rate of 0.01 to minimize loss optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001).minimize(loss) @@ -48,7 +48,7 @@ writer = tf.summary.FileWriter('./graphs/linear_reg', sess.graph) # Step 8: train the model - for i in range(50): # train the model 100 epochs + for i in range(100): # train the model 100 epochs total_loss = 0 for x, y in data: # Session runs train_op and fetch values of loss @@ -67,4 +67,4 @@ plt.plot(X, Y, 'bo', label='Real data') plt.plot(X, X * w + b, 'r', label='Predicted data') plt.legend() -plt.show() \ No newline at end of file +plt.show() diff --git a/examples/03_logistic_regression_mnist_sol.py b/examples/03_logistic_regression_mnist_sol.py index 33a74d68..7c7b3587 100644 --- a/examples/03_logistic_regression_mnist_sol.py +++ b/examples/03_logistic_regression_mnist_sol.py @@ -20,7 +20,7 @@ # Step 1: Read in data # using TF Learn's built in function to load MNIST data to the folder data/mnist -mnist = input_data.read_data_sets('/data/mnist', one_hot=True) +mnist = input_data.read_data_sets('./data/mnist', one_hot=True) # Step 2: create placeholders for features and labels # each image in the MNIST data is of shape 28*28 = 784 @@ -84,7 +84,7 @@ for i in range(n_batches): X_batch, Y_batch = mnist.test.next_batch(batch_size) accuracy_batch = sess.run([accuracy], feed_dict={X: X_batch, Y:Y_batch}) - total_correct_preds += accuracy_batch + total_correct_preds += accuracy_batch[0] print('Accuracy {0}'.format(total_correct_preds/mnist.test.num_examples))