Deep learning with Tensorflow in R

21
Deep Learning and Tensorflow in R Mikael Huss, SciLifeLab Stockholm 6 Dec 2016, SRUG

Transcript of Deep learning with Tensorflow in R

Page 1: Deep learning with Tensorflow in R

Deep Learning and Tensorflow in RMikael Huss, SciLifeLab Stockholm6 Dec 2016, SRUG

Page 2: Deep learning with Tensorflow in R

Neural networks

Page 3: Deep learning with Tensorflow in R

Walter Pitts & Warren McCulloch – McCulloch & Pitts neuron model (1943)http://nautil.us/issue/21/information/the-man-who-tried-to-redeem-the-world-with-logic

“McCulloch was a confident, gray-eyed, wild-bearded, chain-smoking philosopher-poet who lived on whiskey and ice cream and never went to bed before 4 a.m. (…) Pitts was a homeless runaway (...)”

Frank Rosenblatt: perceptron (1958)

Page 4: Deep learning with Tensorflow in R

Multi-layer perceptron

Try to predict the output from the input.The weights are continuously adjusted based on how wrong you are(the difference between the desired output and the actual output)

Page 5: Deep learning with Tensorflow in R

http://playground.tensorflow.org

Page 6: Deep learning with Tensorflow in R

What has made deep learning work?

• The access to sufficiently large data sets for training• GPUs and general increases in computing power• Certain practical “tricks”

The pace of adoption helped by GitHub and other code sharing sites, frameworks likeTensorFlow (Google), Torch (Facebook), Theano (University of Toronto) etc

Page 7: Deep learning with Tensorflow in R

Convolutional neural networks

Convolutional networks (convnets)

Good for image recognition

Filters are learned, not hand-crafted

http://cs231n.github.io/convolutional-networks/

Demo http://cs231n.stanford.edu/

Page 8: Deep learning with Tensorflow in R

Recurrent neural networksUsed for sequence modelling, e g language models

http://karpathy.github.io/2015/05/21/rnn-effectiveness/

http://colah.github.io/posts/2015-08-Understanding-LSTMs/

Can be used as generative models for language

Page 9: Deep learning with Tensorflow in R

9

(Stacked) Autoencoder

Le et al (Stanford/Google): “Building high-level features using large scale unsupervised learning”

Page 10: Deep learning with Tensorflow in R

Generative adversarial networks

Machine generated bedrooms

Walking through “bedroom space”

https://github.com/Newmu/dcgan_code

Page 11: Deep learning with Tensorflow in R

Tensorflow

• First introduced Nov 2015 by Google• Python and C++ APIs• Numerical computations. “Tensors” should

here be understood as multi-dimensional arrays

• Introduced for R in Nov 2016 by RStudio

Page 12: Deep learning with Tensorflow in R

Basic Tensorflow mechanics

• First define a computation graph (~ operations that depend on each other)

• Then execute the graph in a “session”.• Computations can be parallelized on CPU

and/or GPU

Page 13: Deep learning with Tensorflow in R

Example from https://rstudio.github.io/tensorflow/

Page 14: Deep learning with Tensorflow in R

Example from https://rstudio.github.io/tensorflow/

Define a loss function to specify what you are trying to optimize for, and choose an optimizer.

Initialize things. Need to have a “session”.

Page 15: Deep learning with Tensorflow in R

Example from https://rstudio.github.io/tensorflow/

Run the model.

Page 16: Deep learning with Tensorflow in R

For examples of how to build up feed-forward and convolutional networks in this way, see one of many tutorials, e g https://rstudio.github.io/tensorflow/tutorial_mnist_beginners.htmlhttps://rstudio.github.io/tensorflow/tutorial_mnist_pros.html

Page 17: Deep learning with Tensorflow in R

Visualizing your model structure (Tensorboard)

https://github.com/rstudio/tensorflow/blob/master/inst/examples/mnist/mnist_with_summaries.R

Page 18: Deep learning with Tensorflow in R

If you don’t want to build a network from scratch …

(there are many others)

https://www.r-bloggers.com/image-classification-in-r-using-trained-tensorflow-models/

Page 19: Deep learning with Tensorflow in R

VGG16 classification model

Page 20: Deep learning with Tensorflow in R

R Tensorflow installation

https://gist.github.com/hussius/a94ab500ea7ccbfc2de8ab9a50854bd8

Complication: does not currently work with Anaconda Python versions

Page 21: Deep learning with Tensorflow in R

Resources

“Hello, Tensorflow”: https://www.oreilly.com/learning/hello-tensorflow

Convolutional network explanation: http://cs231n.github.io/convolutional-networks/

Recursive network explanation http://karpathy.github.io/2015/05/21/rnn-effectiveness/

The VGG16 Shiny app https://github.com/hussius/shiny-imageclassif-tfslim