User Tools

Site Tools


cs501r_f2016:tmp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
cs501r_f2016:tmp [2016/09/19 17:18]
wingated
cs501r_f2016:tmp [2016/11/09 18:19]
wingated
Line 1: Line 1:
 ====Objective:​==== ====Objective:​====
  
-To explore deeper networks, ​to leverage convolutions, and to explore Tensorboard.+To gain experience coding a DNN architecture and learning program end-to-end, and to gain experience with Siamese network and ResNets.
  
 ---- ----
 ====Deliverable:​==== ====Deliverable:​====
  
-{{ :​cs501r_f2016:​screen_shot_2016-09-19_at_11.16.48_am.png?​direct&​200|}}+For this lab, you will need to implement a simple face similarity detector.
  
-For this lab, you will need to perform three steps:+  - You must implement a siamese network that accepts two input images 
 +  - The network must output the probability that the two images are the same class 
 +  - Your implementation should use a ResNet architecture
  
-  - You need to implement ​the [[https://​www.tensorflow.org/​versions/​r0.10/​tutorials/​index.html|Deep MNIST for experts tutorial]] +You should turn in the following:
-  - You need to modify the tutorial code to deliver visualizations via Tensorboard.+
  
-Specifically,​ you should ​ turn in an iPython notebook that shows two images: +  ​- A tensorboard screenshot ​showing ​that your architecture ​is, indeed, a siamese architecture 
-  ​- A Tensorboard image showing your cost function and classification accuracy over time (using the training set accuracy ​is fine) +  - Your code 
-  - A Tensorboard image showing your (expandedcomputation graph+  - A small writeup ​(<1/2 pagedescribing your test/​training split, your resnet architecture,​ and the final performance of your classifier.
  
-An example of the cost function ​classification accuracies are shown at the right An example of the expanded computation graph is shown down below (Note the "​Download PNG" button ​in the upper-left of Tensorboard!) +You should use the [[http://www.openu.ac.il/​home/​hassner/​data/​lfwa/​|Labeled Faces in the Wild-a]] dataset (also available ​for  
- +[[http://​liftothers.org/​byu/​lfwa.tar.gz|download from liftothers]].
-According to the tutorial, if you run for 20,000 iterations, the final accuracy of your classifier will be around 99.5% To make your life simpler, you only need to run for 1500 iterations My final accuracy was 97.1%+
  
 ---- ----
Line 26: Line 26:
 Your notebook will be graded on the following: Your notebook will be graded on the following:
  
-  * 40% Correct ​multilayer convolutional ​network ​defined and working +  * 35% Correct ​implementation of Siamese ​network 
-  * 30Tidy and legible display ​of Tensorboard accuracy / cost function +  * 35Correct implementation ​of Resnet 
-  * 30Tidy and legible display of Tensorboard computation graph+  * 20Reasonable effort to find a good-performing topology 
 +  * 10% Results writeup
  
 ---- ----
 ====Description:​==== ====Description:​====
  
-You now understand the basics of multi-layer neural networks. ​ Here, we'll expand on your toolkit by adding in convolutions,​ a bit of dropout, and a new optimization method. ​ Most of these will be explained in future lectures, so for now we will just use them without (fully) understanding them. 
  
-**Part 1: implement deep convolutional networks **+<code python>
  
-For this lab, you must implement the [[https://​www.tensorflow.org/​versions/​r0.10/​tutorials/​index.html|Deep MNIST for experts tutorial]]. ​ This is mostly cutting-and-pasting code; since you already have Tensorflow up and running, this should be fairly straightfoward.+from PIL import Image 
 +import numpy as np
  
-A few things to note:+
 +# assumes list.txt is a list of filenames, formatted as 
 +
 +# ./​lfw2//​Aaron_Eckhart/​Aaron_Eckhart_0001.jpg 
 +# ./​lfw2//​Aaron_Guiel/​Aaron_Guiel_0001.jpg 
 +# ... 
 +#
  
-  - You are now adding multiple layers. ​ Be careful with your variable names! +files = open( './list.txt' ).readlines()
-  - You'll use the Adam optimizer, not vanilla SGD We learn more about this later. +
-  - The dropout layer is optional, but you should probably leave it in just to make cutting-and-pasting easier.+
  
-**Note:** you only need to train for 1500 steps My final accuracy was 97.1%although it varied from run to run If you want to train for the full 20k stepsyou are of course welcome to do so!+data = np.zeros(( len(files)250, 250 )) 
 +labels = np.zeros(( len(files)1 ))
  
-**Part 2: add in Tensorboard visualizations**+# a little hash map mapping subjects to IDs 
 +ids = {} 
 +scnt = 0
  
-{{ :cs501r_f2016:​graph-run_2_.png?​direct&​200|}}+# load in all of our images 
 +ind = 0 
 +for fn in files:
  
-There are two parts to this: first, you need to scope all of the nodes in your computation graph. ​ In class, I showed a visualization that drew pretty boxes around all of the different parts of your computation graph That's what I want from you!  Check out the ''​tf.name_scope''​ function You should create 4 scopes"​Wx_B"​ for your computation graph"​Cost"​ for your cost function"​accuracy"​ for your accuracy calculations,​ and "​optimizer"​ for your optimizer When you're done, you should have something that looks like the graph on the right.+    subject = fn.split('/')[3] 
 +    if not ids.has_key( subject ): 
 +        ids[ subject ] = scnt 
 +        scnt += 1 
 +    label = ids[ subject ] 
 +     
 +    data[ ind:: ] = np.array( Image.open( fn.rstrip() ) ) 
 +    labels[ ind ] = label 
 +    ind += 1
  
-Secondyou'll need to produce little graphs that show accuracy over time.  You should record your accuracy every 10 iterations.+# data is (13233250, 250) 
 +# labels is (13233, 1)
  
-This is done by asking Tensorflow to create summaries of key variables. ​ Adventurous souls can dive right into the [[https://​www.tensorflow.org/​versions/​r0.10/​how_tos/​summaries_and_tensorboard/​index.html|Tensorflow visualization tutorial]]. ​ Here are some condensed notes: 
- 
-Tensorboard logs //events// to a //summary log//​. ​ You'll need to tell Tensorboard where to stash those events and when to write them out; both are done with a SummaryWriter. ​ You need to create a SummaryWriter object: 
- 
-''​summary_writer = tf.train.SummaryWriter( "​./​tf_logs",​ graph=sess.graph )''​ 
- 
-as well as scalar summaries of relevant variables; maybe something like this: 
- 
-''​acc_summary = tf.scalar_summary( '​accuracy',​ accuracy )''​ 
- 
-These summaries are considered ops, just like any node in the computation graph, and they are triggered by ''​sess.run''​. ​ Tensorflow helpfully allows you to merge all of the summary ops into a single operation: 
- 
-''​merged_summary_op = tf.merge_all_summaries()''​ 
- 
-Then, you'll need to trigger the ''​merged_summary_op''​ operation. ​ This will generate a //summary string//, which you should pass to your summary writer. 
- 
-Once you have run your code and collected the necessary statistics, you should be able to start up the Tensorboard visualizer. ​ It runs as a webserver; to start Tensorboard,​ you should be able to run something like the following **from the directory where you ran your TF code**: 
- 
-<code bash> 
-cd tf_logs 
-tensorboard --logdir . 
 </​code>​ </​code>​
- 
-At which point you'll see something like the following output: 
- 
-<​code>​ 
-Starting TensorBoard 28 on port 6006 
-(You can navigate to http://​192.168.250.107:​6006) 
-</​code>​ 
- 
-Point your browser to the spot indicated, and voila! 
- 
----- 
-====Hints:​==== 
- 
-Make sure you close your ''​SummaryWriter''​ object at the end of your script, or else your accuracy / cross entropy graphs may not show up! 
- 
-Tensorboard seems a little finnicky. ​ I have found that I sometimes need to stop it and restart it to avoid having multiple graphs overlap, even if I remove the log files. 
- 
- 
cs501r_f2016/tmp.txt · Last modified: 2021/06/30 23:42 (external edit)