By R Studio: details here
devtools::install_github("rstudio/keras")
For those using Conda
Using your own python setup
pip install keras
## [1] "Hello world!"
model <- keras_model_sequential() # Open an interface to tensorflow
# Set up the neural network
model %>%
layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
layer_dropout(rate = 0.4) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')
That’s it. Keras makes it easy.
summary()
on the model to see what we built## Model: "sequential_1"
## ________________________________________________________________________________
## Layer (type) Output Shape Param #
## ================================================================================
## dense (Dense) (None, 256) 200960
## ________________________________________________________________________________
## dropout (Dropout) (None, 256) 0
## ________________________________________________________________________________
## dense_1 (Dense) (None, 128) 32896
## ________________________________________________________________________________
## dropout_1 (Dropout) (None, 128) 0
## ________________________________________________________________________________
## dense_2 (Dense) (None, 10) 1290
## ================================================================================
## Total params: 235,146
## Trainable params: 235,146
## Non-trainable params: 0
## ________________________________________________________________________________
## $loss
## [1] 0.1117176
##
## $accuracy
## [1] 0.9812
Example output of AlexNet
The first (of 5) layers learned
Inputs:
Input and autoencoder
Generated celebrity images
Input
Output
Goal: Build a classifier based on the images’ content
## Model: "sequential"
## ________________________________________________________________________________
## Layer (type) Output Shape Param #
## ================================================================================
## conv2d (Conv2D) (None, 254, 254, 32) 896
## ________________________________________________________________________________
## re_lu (ReLU) (None, 254, 254, 32) 0
## ________________________________________________________________________________
## conv2d_1 (Conv2D) (None, 252, 252, 16) 4624
## ________________________________________________________________________________
## leaky_re_lu (LeakyReLU) (None, 252, 252, 16) 0
## ________________________________________________________________________________
## batch_normalization (BatchNormaliza (None, 252, 252, 16) 64
## ________________________________________________________________________________
## max_pooling2d (MaxPooling2D) (None, 126, 126, 16) 0
## ________________________________________________________________________________
## dropout (Dropout) (None, 126, 126, 16) 0
## ________________________________________________________________________________
## flatten (Flatten) (None, 254016) 0
## ________________________________________________________________________________
## dense (Dense) (None, 20) 5080340
## ________________________________________________________________________________
## activation (Activation) (None, 20) 0
## ________________________________________________________________________________
## dropout_1 (Dropout) (None, 20) 0
## ________________________________________________________________________________
## dense_1 (Dense) (None, 2) 42
## ________________________________________________________________________________
## activation_1 (Activation) (None, 2) 0
## ================================================================================
## Total params: 5,085,966
## Trainable params: 5,085,934
## Non-trainable params: 32
## ________________________________________________________________________________
eval <- model %>%
evaluate_generator(img_test,
steps = as.integer(test_samples / batch_size),
workers = 4)
eval
## $loss
## [1] 0.7535837
##
## $accuracy
## [1] 0.6572581
## Model: "sequential_2"
## ________________________________________________________________________________
## Layer (type) Output Shape Param #
## ================================================================================
## conv2d_4 (Conv2D) (None, 62, 62, 96) 34944
## ________________________________________________________________________________
## re_lu_2 (ReLU) (None, 62, 62, 96) 0
## ________________________________________________________________________________
## max_pooling2d_2 (MaxPooling2D) (None, 31, 31, 96) 0
## ________________________________________________________________________________
## batch_normalization_2 (BatchNormali (None, 31, 31, 96) 384
## ________________________________________________________________________________
## conv2d_5 (Conv2D) (None, 21, 21, 256) 2973952
## ________________________________________________________________________________
## re_lu_3 (ReLU) (None, 21, 21, 256) 0
## ________________________________________________________________________________
## max_pooling2d_3 (MaxPooling2D) (None, 10, 10, 256) 0
## ________________________________________________________________________________
## batch_normalization_3 (BatchNormali (None, 10, 10, 256) 1024
## ________________________________________________________________________________
## conv2d_6 (Conv2D) (None, 8, 8, 384) 885120
## ________________________________________________________________________________
## re_lu_4 (ReLU) (None, 8, 8, 384) 0
## ________________________________________________________________________________
## batch_normalization_4 (BatchNormali (None, 8, 8, 384) 1536
## ________________________________________________________________________________
## conv2d_7 (Conv2D) (None, 6, 6, 384) 1327488
## ________________________________________________________________________________
## re_lu_5 (ReLU) (None, 6, 6, 384) 0
## ________________________________________________________________________________
## batch_normalization_5 (BatchNormali (None, 6, 6, 384) 1536
## ________________________________________________________________________________
## conv2d_8 (Conv2D) (None, 4, 4, 384) 1327488
## ________________________________________________________________________________
## re_lu_6 (ReLU) (None, 4, 4, 384) 0
## ________________________________________________________________________________
## max_pooling2d_4 (MaxPooling2D) (None, 2, 2, 384) 0
## ________________________________________________________________________________
## batch_normalization_6 (BatchNormali (None, 2, 2, 384) 1536
## ________________________________________________________________________________
## flatten_2 (Flatten) (None, 1536) 0
## ________________________________________________________________________________
## dense_4 (Dense) (None, 4096) 6295552
## ________________________________________________________________________________
## activation_4 (Activation) (None, 4096) 0
## ________________________________________________________________________________
## dropout_4 (Dropout) (None, 4096) 0
## ________________________________________________________________________________
## batch_normalization_7 (BatchNormali (None, 4096) 16384
## ________________________________________________________________________________
## dense_5 (Dense) (None, 4096) 16781312
## ________________________________________________________________________________
## activation_5 (Activation) (None, 4096) 0
## ________________________________________________________________________________
## dropout_5 (Dropout) (None, 4096) 0
## ________________________________________________________________________________
## batch_normalization_8 (BatchNormali (None, 4096) 16384
## ________________________________________________________________________________
## dense_6 (Dense) (None, 1000) 4097000
## ________________________________________________________________________________
## activation_6 (Activation) (None, 1000) 0
## ________________________________________________________________________________
## dropout_6 (Dropout) (None, 1000) 0
## ________________________________________________________________________________
## batch_normalization_9 (BatchNormali (None, 1000) 4000
## ________________________________________________________________________________
## dense_7 (Dense) (None, 2) 2002
## ________________________________________________________________________________
## activation_7 (Activation) (None, 2) 0
## ================================================================================
## Total params: 33,767,642
## Trainable params: 33,746,250
## Non-trainable params: 21,392
## ________________________________________________________________________________
YOLOv3
You Only Look Once: Because the algorithm only does one pass (looks once) to classify any and all objects
Yolo model and graphing tool from lutzroeder/netron
Diagram from What’s new in YOLO v3 by Ayoosh Kathuria
Think about how facial recognition showed up everywhere for images over the past few years
What creative uses for the techniques discussed today do you expect to see become reality in accounting in the next 3-5 years?
Today, we:
package:kableExtra
package:keras
package:knitr
package:tidyverse