diff --git a/01 cats vs dogs/input_data.py b/01 cats vs dogs/input_data.py index 69f27f0..ef994f6 100644 --- a/01 cats vs dogs/input_data.py +++ b/01 cats vs dogs/input_data.py @@ -1,6 +1,11 @@ #By @Kevin Xu #kevin28520@gmail.com +# 11.08 2017 更新 +# 最近入驻了网易云课堂讲师,我的第一门课《使用亚马逊云计算训练深度学习模型》。 +# 有兴趣的同学可以学习交流。 +# * 我的网易云课堂主页: http://study.163.com/provider/400000000275062/index.htm + # 深度学习QQ群, 1群满): 153032765 # 2群:462661267 #The aim of this project is to use TensorFlow to process our own data. diff --git a/01 cats vs dogs/new_version/train_and_val.py b/01 cats vs dogs/new_version/train_and_val.py index c22ec23..74b989a 100644 --- a/01 cats vs dogs/new_version/train_and_val.py +++ b/01 cats vs dogs/new_version/train_and_val.py @@ -69,7 +69,7 @@ def run_training(): x = tf.placeholder(tf.float32, shape=[BATCH_SIZE, IMG_W, IMG_H, 3]) - y_ = tf.placeholder(tf.int16, shape=[BATCH_SIZE]) + y_ = tf.placeholder(tf.int32, shape=[BATCH_SIZE]) logits = model.inference(x, BATCH_SIZE, N_CLASSES) loss = model.losses(logits, y_) @@ -98,7 +98,7 @@ def run_training(): feed_dict={x:tra_images, y_:tra_labels}) if step % 50 == 0: print('Step %d, train loss = %.2f, train accuracy = %.2f%%' %(step, tra_loss, tra_acc*100.0)) - summary_str = sess.run(summary_op) + summary_str = sess.run(summary_op, feed_dict={x:tra_images, y_:tra_labels}) train_writer.add_summary(summary_str, step) if step % 200 == 0 or (step + 1) == MAX_STEP: @@ -106,7 +106,7 @@ def run_training(): val_loss, val_acc = sess.run([loss, acc], feed_dict={x:val_images, y_:val_labels}) print('** Step %d, val loss = %.2f, val accuracy = %.2f%% **' %(step, val_loss, val_acc*100.0)) - summary_str = sess.run(summary_op) + summary_str = sess.run(summary_op, feed_dict={x:tra_images, y_:tra_labels}) val_writer.add_summary(summary_str, step) if step % 2000 == 0 or (step + 1) == MAX_STEP: diff --git a/01 cats vs dogs/training.py b/01 cats vs dogs/training.py index decff16..8621183 100644 --- a/01 cats vs dogs/training.py +++ b/01 cats vs dogs/training.py @@ -161,8 +161,59 @@ def run_training(): # print('This is a cat with possibility %.6f' %prediction[:, 0]) # else: # print('This is a dog with possibility %.6f' %prediction[:, 1]) - - +# +def evaluate_all_image(): + ''' + Test all image against the saved models and parameters. + Return global accuracy of test_image_set + ############################################## + ##Notice that test image must has label to compare the prediction and real + ############################################## + ''' + # you need to change the directories to yours. + test_dir = '/home/kevin/tensorflow/cats_vs_dogs/data/test/' + N_CLASSES = 2 + print('-------------------------') + test, test_label = input_data.get_files(test_dir) + BATCH_SIZE = len(test) + print('There are %d test images totally..' % BATCH_SIZE) + print('-------------------------') + test_batch, test_label_batch = input_data.get_batch(test, + test_label, + IMG_W, + IMG_H, + BATCH_SIZE, + CAPACITY) + + logits = model.inference(test_batch, BATCH_SIZE, N_CLASSES) + testloss = model.losses(logits, test_label_batch) + testacc = model.evaluation(logits, test_label_batch) + + logs_train_dir = '/home/kevin/tensorflow/cats_vs_dogs/logs/train/' + saver = tf.train.Saver() + + with tf.Session() as sess: + print("Reading checkpoints...") + ckpt = tf.train.get_checkpoint_state(logs_train_dir) + if ckpt and ckpt.model_checkpoint_path: + global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1] + saver.restore(sess, ckpt.model_checkpoint_path) + print('Loading success, global_step is %s' % global_step) + else: + print('No checkpoint file found') + print('-------------------------') + coord = tf.train.Coordinator() + threads = tf.train.start_queue_runners(sess=sess, coord=coord) + test_loss,test_acc = sess.run([testloss,testacc]) + print('The model\'s loss is %.2f' %test_loss) + correct = int(BATCH_SIZE*test_acc) + print('Correct : %d' % correct) + print('Wrong : %d' % (BATCH_SIZE - correct)) + print('The accuracy in test images are %.2f%%' %(test_acc*100.0)) + coord.request_stop() + coord.join(threads) + sess.close() + #%% diff --git a/02 CIFAR10/cifar10.py b/02 CIFAR10/cifar10.py index 9bc8a7b..34cb988 100644 --- a/02 CIFAR10/cifar10.py +++ b/02 CIFAR10/cifar10.py @@ -1,6 +1,9 @@ -#By @Kevin Xu -#kevin28520@gmail.com -#Youtube: https://www.youtube.com/channel/UCVCSn4qQXTDAtGWpWAe4Plw +# 11.08 2017 更新 +# 最近入驻了网易云课堂讲师,我的第一门课《使用亚马逊云计算训练深度学习模型》。 +# 有兴趣的同学可以学习交流。 +# * 我的网易云课堂主页: http://study.163.com/provider/400000000275062/index.htm + + #Chinese weibo: http://bit.ly/2nAmOcO @@ -305,4 +308,4 @@ def evaluate(): - \ No newline at end of file + diff --git a/03 TFRecord/README.md b/03 TFRecord/README.md index e4d3639..ef66fbb 100644 --- a/03 TFRecord/README.md +++ b/03 TFRecord/README.md @@ -1,3 +1,9 @@ +# 11.08 2017 更新 +最近入驻了网易云课堂讲师,我的第一门课《使用亚马逊云计算训练深度学习模型》。 +有兴趣的同学可以学习交流。 +* 我的网易云课堂主页: http://study.163.com/provider/400000000275062/index.htm +--- + # How to transform our data into TFRecord? 1. transform data into TFRecord format 2. read TFRecord file diff --git a/04 VGG Tensorflow/readme.md b/04 VGG Tensorflow/readme.md index d71ac5d..ea8cb6e 100644 --- a/04 VGG Tensorflow/readme.md +++ b/04 VGG Tensorflow/readme.md @@ -1,3 +1,9 @@ +# 11.08 2017 更新 +最近入驻了网易云课堂讲师,我的第一门课《使用亚马逊云计算训练深度学习模型》。 +有兴趣的同学可以学习交流。 +* 我的网易云课堂主页: http://study.163.com/provider/400000000275062/index.htm +--- + # VGG with Tensorflow 1. VGG paper review diff --git a/04 VGG Tensorflow/training_and_val.py b/04 VGG Tensorflow/training_and_val.py index ff98148..bc49782 100644 --- a/04 VGG Tensorflow/training_and_val.py +++ b/04 VGG Tensorflow/training_and_val.py @@ -92,7 +92,7 @@ def train(): feed_dict={x:tra_images, y_:tra_labels}) if step % 50 == 0 or (step + 1) == MAX_STEP: print ('Step: %d, loss: %.4f, accuracy: %.4f%%' % (step, tra_loss, tra_acc)) - summary_str = sess.run(summary_op) + summary_str = sess.run(summary_op, feed_dict={x:tra_images, y_:tra_labels}) tra_summary_writer.add_summary(summary_str, step) if step % 200 == 0 or (step + 1) == MAX_STEP: @@ -101,7 +101,7 @@ def train(): feed_dict={x:val_images,y_:val_labels}) print('** Step %d, val loss = %.2f, val accuracy = %.2f%% **' %(step, val_loss, val_acc)) - summary_str = sess.run(summary_op) + summary_str = sess.run(summary_op, feed_dict={x:tra_images, y_:tra_labels}) val_summary_writer.add_summary(summary_str, step) if step % 2000 == 0 or (step + 1) == MAX_STEP: diff --git a/README.md b/README.md index 4010d68..be9bd9b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ +## (Note that this repo is NOT going to be updated anymore, tensorflow version used in this repo was very old. -- July 19th, 2018) + # My-TensorFlow-tutorials -1. This repo contains my computer vision projects. -2. My interests: - - computer vision - - deep learning +This repo contains Tensorflow & deep learning projects. +1. Deep Learning (as well as traditional Machine Learning, Data Mining). +2. Tensorflow, Keras -# Where to find me (for Chinese readers)? -* Youtube: https://www.youtube.com/c/KevinXu (videos were recorded in Chinese, 中文视频) -* 微博: http://weibo.com/3983872447/profile -* 优酷: http://i.youku.com/deeplearning101 -* 深度学习QQ群: 153032765 (人满), 2群:462661267(人满), 3群:264976854 +* Youtube: https://www.youtube.com/c/KevinXu +