Lecture note 7: Playing with convolutions in TensorFlow

Similar documents
Lecture note 4: How to structure your model in TensorFlow

CS224n: Natural Language Processing with Deep Learning 1

Machine Learning Workshop

CNN Basics. Chongruo Wu

Monday Morning Haskell 1. Haskell Tensor Flow Guide

Deep Learning For Video Classification. Presented by Natalie Carlebach & Gil Sharon

! References: ! Computer eyesight gets a lot more accurate, NY Times. ! Stanford CS 231n. ! Christopher Olah s blog. ! Take ECS 174!

Basic Models in TensorFlow. CS 20SI: TensorFlow for Deep Learning Research Lecture 3 1/20/2017

Manage Experiments. CS 20SI: TensorFlow for Deep Learning Research Lecture 5 1/27/2017

Natural Language Processing CS 6320 Lecture 6 Neural Language Models. Instructor: Sanda Harabagiu

Separable Kernels and Edge Detection

Keras: Handwritten Digit Recognition using MNIST Dataset

CS 523: Multimedia Systems

R for SQListas, a Continuation

Convolu'onal Neural Networks

CIS680: Vision & Learning Assignment 2.b: RPN, Faster R-CNN and Mask R-CNN Due: Nov. 21, 2018 at 11:59 pm

Convolutional Neural Networks (CNN)

Index. Umberto Michelucci 2018 U. Michelucci, Applied Deep Learning,

Machine Learning 13. week

DECISION SUPPORT SYSTEM USING TENSOR FLOW

Keras: Handwritten Digit Recognition using MNIST Dataset

TensorFlow for Deep Learning

CS1114 Section 8: The Fourier Transform March 13th, 2013

Machine Learning With Python. Bin Chen Nov. 7, 2017 Research Computing Center

CS 179 Lecture 16. Logistic Regression & Parallel SGD

Perceptron: This is convolution!

CIS 660. Image Searching System using CNN-LSTM. Presented by. Mayur Rumalwala Sagar Dahiwala

Inception and Residual Networks. Hantao Zhang. Deep Learning with Python.

Know your data - many types of networks

C-Brain: A Deep Learning Accelerator

Deep Learning Explained Module 4: Convolution Neural Networks (CNN or Conv Nets)

SEMANTIC COMPUTING. Lecture 8: Introduction to Deep Learning. TU Dresden, 7 December Dagmar Gromann International Center For Computational Logic

Deep Learning for Computer Vision with MATLAB By Jon Cherrie

Machine Learning on Encrypted Data

ndpi & Machine Learning A future concrete idea

INTRODUCTION TO DEEP LEARNING

Hello Edge: Keyword Spotting on Microcontrollers

Lecture 2: SML Basics

OPENSEQ2SEQ: A DEEP LEARNING TOOLKIT FOR SPEECH RECOGNITION, SPEECH SYNTHESIS, AND NLP

Generative Modeling with Convolutional Neural Networks. Denis Dus Data Scientist at InData Labs

Midterm Review. CS230 Fall 2018

Deep Learning and Its Applications

Lecture 37: ConvNets (Cont d) and Training

Lecture 1: Overview

Machine Learning. Deep Learning. Eric Xing (and Pengtao Xie) , Fall Lecture 8, October 6, Eric CMU,

Intro to Deep Learning. Slides Credit: Andrej Karapathy, Derek Hoiem, Marc Aurelio, Yann LeCunn

Introduction to TensorFlow. Mor Geva, Apr 2018

Channel Locality Block: A Variant of Squeeze-and-Excitation

Neural Nets & Deep Learning

CSE 559A: Computer Vision

Convolutional Neural Networks

CS 224n: Assignment #5

A performance comparison of Deep Learning frameworks on KNL

All You Want To Know About CNNs. Yukun Zhu

textures not patterns

Lecture 3: Overview of Deep Learning System. CSE599W: Spring 2018

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Java Basics Lecture: January 26, 2012 (On-line Lecture 1)

A Quick Guide on Training a neural network using Keras.

MIXED PRECISION TRAINING: THEORY AND PRACTICE Paulius Micikevicius

Machine Learning: Chenhao Tan University of Colorado Boulder LECTURE 15

3Using and Writing. Functions. Understanding Functions 41. In this chapter, I ll explain what functions are and how to use them.

Clustering algorithms and autoencoders for anomaly detection

Hardware and Software. Fei-Fei Li & Justin Johnson & Serena Yeung. Lecture 6-1

Machine Learning. MGS Lecture 3: Deep Learning

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay.

6. Convolutional Neural Networks

Deep Learning with Torch

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

Weiguang Guan Code & data: guanw.sharcnet.ca/ss2017-deeplearning.tar.gz

ONLINE EVALUATION FOR: Company Name

Homework 01 : Deep learning Tutorial

Convolutional Networks for Text

Introduction to Python Part 2

ASCII Art. Introduction: Python

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Math 2250 Lab #3: Landing on Target

WordPress Tutorial for Beginners with Step by Step PDF by Stratosphere Digital

1.7 Limit of a Function

This is the lesson workshop to create a test page in DIVI

Artificial Intelligence Introduction Handwriting Recognition Kadir Eren Unal ( ), Jakob Heyder ( )

pytorch-nlp-tutorial-sf2017 Documentation

Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset. By Joa õ Carreira and Andrew Zisserman Presenter: Zhisheng Huang 03/02/2018

INF 5860 Machine learning for image classification. Lecture 11: Visualization Anne Solberg April 4, 2018

Tutorial on Keras CAP ADVANCED COMPUTER VISION SPRING 2018 KISHAN S ATHREY

ConvolutionalNN's... ConvNet's... deep learnig

Dynamic Routing Between Capsules

Deep Learning Workshop. Nov. 20, 2015 Andrew Fishberg, Rowan Zellers

Pyramidal Deep Models for Computer Vision

Deep Learning Frameworks. COSC 7336: Advanced Natural Language Processing Fall 2017

PLT: Inception (cuz there are so many layers)

4.7 Approximate Integration

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

Google Earth: Significant Places in Your Life Got Maps? Workshop June 17, 2013

An Introduction to Deep Learning with RapidMiner. Philipp Schlunder - RapidMiner Research

MTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material

Using GitHub to Share with SparkFun a

The Power of Speech: Supporting Voice- Driven Commands in Small, Low-Power. Microcontrollers

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Interactive Tourist Map

Transcription:

Lecture note 7: Playing with convolutions in TensorFlow CS 20SI: TensorFlow for Deep Learning Research (cs20si.stanford.edu) Prepared by Chip Huyen ( huyenn@stanford.edu ) This lecture note is an unfinished draft. Proceed with care! Last class, we had a wonderful guest lecture by Justin Johnson. I hope that by now, you re more or less familiar with common layers of a convolutional neural networks. Today, we will make a (crude) attempt to understand convolution and what kind of support TensorFlow has for convolutions. Understanding convolutions If you ve taken maths or physics, you re probably familiar with this term. Oxford dictionary define the mathematical term convolution as: a function derived from two given functions by integration that expresses how the shape of one is modified by the other. And that s pretty much what convolution means in the neural networks setting. Convolution is how the original input (in the first convolutional layer, it s part of the original image) is modified by the kernel (or filter). To better understand convolutions, you can refer to this wonderful blog post by Chris Olah at Google Brain. Gif from Wikipedia TensorFlow has great support for convolutional layers. The most popular one is tf.nn.conv2d. tf. nn. conv2d ( input, filter, strides, padding, use_cudnn_on_gpu = None, data_format = None, name = None) Input : Batch size x Height x Width x Channels Filter : Height x Width x Input Channels x Output Channels ( e. g. [ 5, 5, 3, 64 ]) Strides : 4 element 1 - D tensor, strides in each direction ( often [ 1, 1, 1, 1 ] or [ 1, 2, 2, 1 ])

Padding : ' SAME ' or ' VALID' Data_format : default to NHWC Generally, for strides, you don t want to use any number other than 1 in the first and the fourth dimension, Because of this property of convolution, we can do convolutions without training anything. We can simply choose a kernel and see how that kernel affects our image. For example, the kernel often used for blurring an image is as below. You can do the element-wise multiplication to see how this kernel helps blurring an image. Kernel for blurring Just as a fun exercise, you can see several other popular kernels in the kernels.py file on the class GitHub repository, and see how to use them in 07_basic_filters.py let s see what the Blurring kernel does to this super cute image of a Chihuahua. There are also several other built-in convolutional operations. Please refer to the official documentation for more information. conv2d : Arbitrary filters that can mix channels together. depthwise_conv2d : Filters that operate on each channel independently. separable_conv2d : A depthwise spatial filter followed by a pointwise filter.

In this case, we hard code our kernels. When training a convnet, we don t know what the values for our kernels and therefore have to figure them out by learning them. We ll go through the process of learning the kernels through a simple convnet with our old friend MNIST. Convnet on MNIST We ve done logistic regression on MNIST and the result is abysmal. Since MNIST dataset contains of just images, let s see how much better we can do with convnet on MNIST. For MNIST, we will be using two convolutional layers, each followed by a relu and a maxpool layers, and one fully connected layer. See the example on GitHub under the name 07_convnet_mnist.py Variable scope Since we ll be dealing with multiple layers, it s important to introduce variable scope. Think of a variable scope something similar to a namespace. A variable name weights in variable scope conv1 will become conv1-weights. The common practice is to create a variable scope for each layer, so that if you have variable weights in both convolution layer 1 and convolution layer 2, there won t be any name clash. In variable scope, we don t create variable using tf.variable, but instead use tf.get_variable() tf. get_variable (< name >, <shape>, <initializer>) If a variable with that name already exists in that variable scope, we use that variable. If a variable with that name doesn t already exists in that variable scope, TensorFlow creates a new variable. This setup makes it really easy to share variables across architecture. This will come in extremely handy when you build complex models and you need to share large sets of variables. Variable scopes help you initialize all of them in one place. Nodes in the same variable scope will be grouped together, and therefore you don t have to use name scope any more. To declare a variable scope, you do it the same way you do name scope:

with tf. variable_scope ( 'conv1' ) as scope: For example: with tf. variable_scope ( 'conv1' ) as scope: w = tf. get_variable ( 'weights', [ 5, 5, 1, 32 ]) b = tf. get_variable ( 'biases', [ 32 ], initializer = tf. random_normal_initializer ()) conv = tf. nn. conv2d ( images, w, strides =[ 1, 1, 1, 1 ], padding = 'SAME') conv1 = tf. nn. relu ( conv + b, name = scope. name) with tf. variable_scope ( 'conv2' ) as scope: w = tf. get_variable ( 'weights', [ 5, 5, 32, 64 ]) b = tf. get_variable ( 'biases', [ 64 ], initializer = tf. random_normal_initializer ()) conv = tf. nn. conv2d ( conv1, w, strides =[ 1, 1, 1, 1 ], padding = 'SAME') conv2 = tf. nn. relu ( conv + b, name = scope. name) You see that with variable scope, we now have neatly block of code that can be broken into smaller function for reusability. For more information on variable scope, please refer to the official documentation.

Below is the training result for MNIST with covnets: Epochs Accuracy 1 0.9111 2 0.9401 3 0.9494 5 0.9549 10 0.9692 25 0.9736 40 0.9793 50 0.9804