Tensorflow in Deep Learning

Slides:



Advertisements
Similar presentations
Social Computing and Big Data Analytics 社群運算與大數據分析 SCBDA10 MIS MBA (M2226) (8628) Wed, 8,9, (15:10-17:00) (B309) Deep Learning with Google TensorFlow.
Advertisements

Bassem Makni SML 16 Click to add text 1 Deep Learning of RDF rules Semantic Machine Learning.
Comparing TensorFlow Deep Learning Performance Using CPUs, GPUs, Local PCs and Cloud Pace University, Research Day, May 5, 2017 John Lawrence, Jonas Malmsten,
Combining Models Foundations of Algorithms and Machine Learning (CS60020), IIT KGP, 2017: Indrajit Bhattacharya.
TensorFlow The Deep Learning Library You Should Be Using.
Welcome deep loria !.
TensorFlow CS 5665 F16 practicum Karun Joseph, A Reference:
TensorFlow– A system for large-scale machine learning
Deep Learning Software: TensorFlow
Reinforcement Learning
Zheng ZHANG 1-st year PhD candidate Group ILES, LIMSI
Getting started with TensorBoard
Tensorflow Tutorial Homin Yoon.
Artificial Neural Networks
Chilimbi, et al. (2014) Microsoft Research
Lecture 3. Fully Connected NN & Hello World of Deep Learning
DeepCount Mark Lenson.
Deep Learning in HEP Large number of applications:
COMP24111: Machine Learning and Optimisation
Applications of Deep Learning and how to get started with implementation of deep learning Presentation By : Manaswi Advisor : Dr.Chinmay.
Deep Learning Libraries
Intro to NLP and Deep Learning
CS 224S: TensorFlow Tutorial
Coding in Python and Basics of Tensorflow
Neural Networks CS 446 Machine Learning.
Classification with Perceptrons Reading:
Deep Learning with TensorFlow online Training at GoLogica Technologies
Intelligent Information System Lab
Overview of TensorFlow
A VERY Brief Introduction to Convolutional Neural Network using TensorFlow 李 弘
Comparison Between Deep Learning Packages
Policy Compression for MDPs
Deep Learning Workshop
TensorFlow and Clipper (Lecture 24, cs262a)
Introduction to CuDNN (CUDA Deep Neural Nets)
Neural Networks and Backpropagation
A brief introduction to neural network
Introduction to Deep Learning for neuronal data analyses
INF 5860 Machine learning for image classification
Introduction to TensorFlow
Tensorflow in Deep Learning
Introduction to Neural Networks
Deep Learning Packages
Tensorflow in Deep Learning
Introduction to Tensorflow
An open-source software library for Machine Intelligence
MXNet Internals Cyrus M. Vahid, Principal Solutions Architect,
Logistic Regression & Parallel SGD
Introduction to Deep Learning with Keras
MNIST Dataset Training with Tensorflow
CSC 578 Neural Networks and Deep Learning
Neural Networks Geoff Hulten.
Vinit Shah, Joseph Picone and Iyad Obeid
Debugging Dataflow Graphs using TensorFlow Debugger.
Coding neural networks: A gentle Introduction to keras
Tensorflow Tutorial Presented By :- Ankur Mali
Image Classification & Training of Neural Networks
Presentation By: Eryk Helenowski PURE Mentor: Vincent Bindschaedler
Tensorflow Lecture 박 영 택 컴퓨터학부.
TensorFlow: A System for Large-Scale Machine Learning
Introduction to TensorFlow
Deep Learning Libraries
What's New in eCognition 9
CSC 578 Neural Networks and Deep Learning
Getting started with TensorBoard
Deep Learning with TensorFlow
Tensorflow in Deep Learning
An introduction to neural network and machine learning
Overall Introduction for the Lecture
Machine Learning for Cyber
Presentation transcript:

Tensorflow in Deep Learning Lecture 1: TensorFlow Basics JAHANDAR JAHANIPOUR jjahanipour@uh.edu www.easy-tensorflow.com https://github.com/easy-tensorflow 30/04/2018 www.easy-tensorflow.com

About Me B.S. Electrical Engineering – IKIU (Iran) M.S. Electrical Engineering – IUT (Iran) PhD Candidate at ECE department - UH Bio-Analytics Lab Research Interests: Deep Learning - Machine Learning – Computer Vision www.easy-tensorflow.com “Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks”, NIPS 2015 Aryan Mohammad Jahandar 30/04/2018 www.easy-tensorflow.com

What Do You Learn at This Workshop ? TensorFlow Basics Datatypes: Efficiently use your memory Graph & Session: Save computation time by running needed operations TensorBoard: Flashlight to your Neural Network BLACK BOX Neural Network AutoEncoder Convolutional Neural Network 30/04/2018 www.easy-tensorflow.com

Outline About TensorFlow TensorFlow Basics What is TensorFlow? Why TensorFlow? TensorFlow Basics Introduction Graph & Session Datatypes Logistic Regression (Linear Classifier) 30/04/2018 www.easy-tensorflow.com

“… software library for Machine Intelligence” What is TensorFlow? “TensorFlow™ is an open source software library for numerical computation using data flow graphs.” “… software library for Machine Intelligence” Created by Google API available for multiple languages (Python, C++, Java, Go, etc.) Suitable for both production & research 30/04/2018 www.easy-tensorflow.com

Companies Using TensorFlow 30/04/2018 www.easy-tensorflow.com

Trends on Different Deep Learning Libraries 30/04/2018 www.easy-tensorflow.com

Drawing with TensorFlow A Neural Representation of Sketch Drawings (Ha et al. 2017) 30/04/2018 www.easy-tensorflow.com

Image Style Transfer with TensorFlow Image Style Transfer Using Convolutional Neural Networks (Gatys et. al. 2016) 30/04/2018 www.easy-tensorflow.com

Why TensorFlow? Developed and maintained by Google Very large and active community + Nice documentation Python API Multi-GPU support TensorBoard (A very Powerful visualization tool) Faster model compilation than Theano-based options High level APIs build on top of TensorFlow (Keras, TFlearn, …) 30/04/2018 www.easy-tensorflow.com

How to Set It Up? Python – Programming language Learn more from: Stanford CS231: Python Numpy Tutorial Corey Schafer Python Tutorial Anaconda – Package manager (Optional; instead of installing Python directly) What is Anaconda? TensorFlow IDE – Editor (preferably PyCharm) http://www.easy-tensorflow.com/install 30/04/2018 www.easy-tensorflow.com

Introduction to TensorFlow What is a Tensor? Multi-dimensional array 0-d tensor: scalar (number) 1-d tensor: vector 2-d tensor: matrix Importing the library import tensorflow as tf “Computational Graph” approach Build the GRAPH which represents the data flow of the computation Run the SESSION which executes the operations on the graph Input tensor for images: [batch_size, image_height, image_width, channels] 30/04/2018 www.easy-tensorflow.com

Graph and Session Graph Nodes = Operations 30/04/2018 www.easy-tensorflow.com

Graph and Session Graph Nodes = Operations Edges = Tensors 30/04/2018 www.easy-tensorflow.com

Graph and Session Graph Session Nodes = Operations Edges = Tensors Tensor = data Tensor + flow = data + flow 30/04/2018 www.easy-tensorflow.com

Graph and Session Example 1: LAZY PROGRAMMING: Call-by-need import tensorflow as tf c = tf.add(2, 3, name='Add') print(c) LAZY PROGRAMMING: Call-by-need DON’T BE LAZY !!!! Graph TensorFlow names the node if you don’t ! 30/04/2018 www.easy-tensorflow.com

Graph and Session ? Example 1: “Computational Graph” approach import tensorflow as tf a = 2 b = 3 c = tf.add(a, b, name='Add') print(c) Graph Variables ? Tensor("Add:0", shape=(), dtype=int32) “Computational Graph” approach Build the GRAPH which represents the data flow of the computation Run the SESSION which executes the operations on the graph 30/04/2018 www.easy-tensorflow.com

Graph and Session Example 1: import tensorflow as tf a = 2 b = 3 c = tf.add(a, b, name='Add') print(c) sess = tf.Session() print(sess.run(c)) sess.close() 5 Graph Variables 30/04/2018 www.easy-tensorflow.com

Graph and Session Example 1: import tensorflow as tf a = 2 b = 3 c = tf.add(a, b, name='Add') print(c) sess = tf.Session() with tf.Session() as sess: print(sess.run(c)) sess.close() 5 Graph Variables 30/04/2018 www.easy-tensorflow.com

Graph and Session Example 2: Graph import tensorflow as tf x = 2 y = 3 add_op = tf.add(x, y, name='Add') mul_op = tf.multiply(x, y, name='Multiply') pow_op = tf.pow(add_op, mul_op, name='Power') with tf.Session() as sess: pow_out = sess.run(pow_op) Graph Variables 30/04/2018 www.easy-tensorflow.com

Graph and Session Example 3: Graph import tensorflow as tf x = 2 y = 3 add_op = tf.add(x, y, name='Add') mul_op = tf.multiply(x, y, name='Multiply') pow_op = tf.pow(add_op, mul_op, name='Power') useless_op = tf.multiply(x, add_op, name='Useless') with tf.Session() as sess: pow_out = sess.run(pow_op) Graph Variables 30/04/2018 www.easy-tensorflow.com

Graph and Session Example 3: Graph import tensorflow as tf x = 2 y = 3 add_op = tf.add(x, y, name='Add') mul_op = tf.multiply(x, y, name='Multiply') pow_op = tf.pow(add_op, mul_op, name='Power') useless_op = tf.multiply(x, add_op, name='Useless') with tf.Session() as sess: [pow_out, useless_out = sess.run([pow_op, useless_op]) Graph Variables 30/04/2018 www.easy-tensorflow.com

Data types Constants are used to create constant values Example tf.constant( value,   dtype=None,   shape=None,   name='Const',   verify_shape=False ) Example s = tf.constant(2, name='scalar') m = tf.constant([[1, 2], [3, 4]], name='matrix') 30/04/2018 www.easy-tensorflow.com

Data types Constants are used to create constant values Before: import tensorflow as tf a = 2 b = 3 c = tf.add(a, b, name='Add') with tf.Session() as sess: print(sess.run(c)) 5 Graph Variables 30/04/2018 www.easy-tensorflow.com

Data types Constants are used to create constant values Now: import tensorflow as tf a = tf.constant(2, name='A') b = tf.constant(3, name='B') c = tf.add(a, b, name='Add') with tf.Session() as sess: print(sess.run(c)) 5 Graph Variables 30/04/2018 www.easy-tensorflow.com

Data types Variables are stateful nodes (=ops) which output their current value They Can be saved and restored Gradient updates will apply to all variables in the graph ⇒ Network Parameters (weights and biases) Example s1 = tf.get_variable(name='scalar1', initializer=2) s2 = tf.get_variable(name='scalar2', initializer=tf.constant(2)) m = tf.get_variable('matrix', initializer=tf.constant([[0, 1], [2, 3]])) M = tf.get_variable('big_matrix', shape=(784, 10), initializer=tf.zeros_initializer()) W = tf.get_variable('weight', shape=(784, 10), initializer=tf.truncated_normal_initializer(mean=0.0, stddev=0.01)) get_variable(     name,     shape=None,     dtype=None,     initializer=None,     regularizer=None,     trainable=True,     collections=None,     caching_device=None,     partitioner=None,     validate_shape=True,     use_resource=None,     custom_getter=None,     constraint=None) 30/04/2018 www.easy-tensorflow.com

Data types ? Variables Graph import tensorflow as tf # create graph a = tf.get_variable(name="A", initializer=tf.constant([[0, 1], [2, 3]])) b = tf.get_variable(name="B", initializer=tf.constant([[4, 5], [6, 7]])) c = tf.add(a, b, name="Add") # launch the graph in a session with tf.Session() as sess: # now we can run the desired operation print(sess.run(c)) Graph Variables ? FailedPreconditionError: Attempting to use uninitialized value 30/04/2018 www.easy-tensorflow.com

Data types Variables Graph import tensorflow as tf # create graph a = tf.get_variable(name="A", initializer=tf.constant([[0, 1], [2, 3]])) b = tf.get_variable(name="B", initializer=tf.constant([[4, 5], [6, 7]])) c = tf.add(a, b, name="Add") # Add an Op to initialize variables init_op = tf.global_variables_initializer() # launch the graph in a session with tf.Session() as sess: # run the variable initializer sess.run(init_op) # now we can run the desired operation print(sess.run(c)) Graph Variables [[ 4  6]  [ 8 10]] 30/04/2018 www.easy-tensorflow.com

Data types Placeholder is a node whose value is fed in at execution time. Assemble the graph without knowing the values needed for computation We can later supply the data at the execution time. ⇒ Input data (in classification task: Inputs and labels) Example a = tf.placeholder(tf.float32, shape=[5]) b = tf.placeholder(dtype=tf.float32, shape=None, name=None) X = tf.placeholder(tf.float32, shape=[None, 784], name='input') Y = tf.placeholder(tf.float32, shape=[None, 10], name='label') tf.placeholder( dtype,     shape=None,     name=None ) 30/04/2018 www.easy-tensorflow.com

Data types ? Placeholder Graph import tensorflow as tf a = tf.constant([5, 5, 5], tf.float32, name='A') b = tf.placeholder(tf.float32, shape=[3], name='B') c = tf.add(a, b, name="Add") with tf.Session() as sess: print(sess.run(c)) Graph Variables ? You must feed a value for placeholder tensor 'B' with dtype float and shape [3] 30/04/2018 www.easy-tensorflow.com

Data types Placeholder Graph import tensorflow as tf a = tf.constant([5, 5, 5], tf.float32, name='A') b = tf.placeholder(tf.float32, shape=[3], name='B') c = tf.add(a, b, name="Add") with tf.Session() as sess: # create a dictionary: d = {b: [1, 2, 3]} # feed it to the placeholder print(sess.run(c, feed_dict=d)) Graph Variables [6. 7. 8.] 30/04/2018 www.easy-tensorflow.com

Final Example Logistic Classifier (linear classifier) D=784 Out=10 30/04/2018 www.easy-tensorflow.com

MNIST Data 28 28 30/04/2018 www.easy-tensorflow.com

Epoch / Iteration … … … … Example: MNIST data - number of training data: N=55,000 - Let’s take batch size of B=100 … … … … First 100 images (=1st iteration) 2nd iteration Last iteration - How many iteration in each epoch? 55000/100 = 550 1 epoch = 550 iteration 30/04/2018 www.easy-tensorflow.com

Logistic Classifier (linear classifier) Set of N labeled inputs: D = {(X1, y1), …, (XN, yN)} 𝑿=𝒊𝒏𝒑𝒖𝒕 𝒅𝒂𝒕𝒂 𝒚=𝒊𝒏𝒑𝒖𝒕 𝒍𝒂𝒃𝒆𝒍 Bias (1,10) 0.0 1.5 0.7 0.4 0.1 3.5 0.2 Weight (784,10) WX+b = y 28 28 (1,784) Logits 30/04/2018 www.easy-tensorflow.com

Logistic Classifier (linear classifier) 0.0 1.5 0.7 0.4 0.1 3.5 0.2 0.02 0.09 0.04 0.03 0.70 1 SOFTMAX Cross-entropy WXn+b 𝐞𝐱𝐩⁡( 𝒚 𝒊 ) 𝒊=𝟎 𝟗 𝐞𝐱𝐩⁡( 𝒚 𝒊 ) Total Loss = 𝟏 𝐍 𝒏 𝐃 𝐒 𝐧 , 𝐋 𝐧 = 𝟏 𝐍 𝐧 𝐃 𝐒 𝐖 𝐗 𝐧 +𝐛 , 𝐋 𝐧 𝑫 𝑺 𝒏 , 𝑳 𝒏 =− 𝒊 𝑳 𝒏 𝒊 𝐥𝐨𝐠⁡( 𝑺 𝒏 𝒊 ) (Superscript: index of elements) Logits (yn) Probs. (S(yn)) One-hot encoded labels (Ln) Input (Xn) 30/04/2018 www.easy-tensorflow.com

Optimizer 𝐋= 𝟏 𝐍 𝐧 𝐃 𝐒 𝐖 𝐗 𝐧 +𝐛 , 𝐋 𝐧 Gradient descent: 𝒘 ≔ 𝒘−𝜶 𝝏𝑳 𝝏𝒘 𝐋= 𝟏 𝐍 𝐧 𝐃 𝐒 𝐖 𝐗 𝐧 +𝐛 , 𝐋 𝐧 Gradient descent: 𝒘 ≔ 𝒘−𝜶 𝝏𝑳 𝝏𝒘 Learning rate An overview of gradient descent optimization algorithms 30/04/2018 www.easy-tensorflow.com

Logistic Classifier (linear classifier) Disadvangates: Few parameters: #parameters = 10x784 + 10 = 7850 At the end, it’s a linear model! Advantages: Linear models are STABLE! 30/04/2018 www.easy-tensorflow.com