TensorFlow APIs for Image Classification. Installing Tensorflow and TFLearn

Similar documents
Python Machine Learning

System Implementation for SemEval-2017 Task 4 Subtask A Based on Interpolated Deep Neural Networks

ADVANCED MACHINE LEARNING WITH PYTHON BY JOHN HEARTY DOWNLOAD EBOOK : ADVANCED MACHINE LEARNING WITH PYTHON BY JOHN HEARTY PDF

Generative models and adversarial training

OPTIMIZATINON OF TRAINING SETS FOR HEBBIAN-LEARNING- BASED CLASSIFIERS

Training a Neural Network to Answer 8th Grade Science Questions Steven Hewitt, An Ju, Katherine Stasaski

Word Segmentation of Off-line Handwritten Documents

Urban Analysis Exercise: GIS, Residential Development and Service Availability in Hillsborough County, Florida

arxiv: v1 [cs.lg] 15 Jun 2015

Deep search. Enhancing a search bar using machine learning. Ilgün Ilgün & Cedric Reichenbach

Lecture 1: Machine Learning Basics

Appendix L: Online Testing Highlights and Script

Lip reading: Japanese vowel recognition by tracking temporal changes of lip shape

Twitter Sentiment Classification on Sanders Data using Hybrid Approach

OCR for Arabic using SIFT Descriptors With Online Failure Prediction

Testing A Moving Target: How Do We Test Machine Learning Systems? Peter Varhol Technology Strategy Research, USA

Introduction to Causal Inference. Problem Set 1. Required Problems

A Simple VQA Model with a Few Tricks and Image Features from Bottom-up Attention

Business Analytics and Information Tech COURSE NUMBER: 33:136:494 COURSE TITLE: Data Mining and Business Intelligence

arxiv: v1 [cs.cv] 10 May 2017

Lip Reading in Profile

1 Instructional Design Website: Making instruction easy for HCPS Teachers Henrico County, Virginia

Test Effort Estimation Using Neural Network

Semantic Segmentation with Histological Image Data: Cancer Cell vs. Stroma

CS Machine Learning

Justin Raisner December 2010 EdTech 503

Android App Development for Beginners

Predicting Student Attrition in MOOCs using Sentiment Analysis and Neural Networks

Analyzing sentiments in tweets for Tesla Model 3 using SAS Enterprise Miner and SAS Sentiment Analysis Studio

Houghton Mifflin Online Assessment System Walkthrough Guide

Using Web Searches on Important Words to Create Background Sets for LSI Classification

CS224d Deep Learning for Natural Language Processing. Richard Socher, PhD

Human Emotion Recognition From Speech

AUTOMATIC DETECTION OF PROLONGED FRICATIVE PHONEMES WITH THE HIDDEN MARKOV MODELS APPROACH 1. INTRODUCTION

Machine Learning and Data Mining. Ensembles of Learners. Prof. Alexander Ihler

Modeling function word errors in DNN-HMM based LVCSR systems

CSL465/603 - Machine Learning

Reducing Features to Improve Bug Prediction

Rule Learning With Negation: Issues Regarding Effectiveness

Read&Write Gold is a software application and can be downloaded in Macintosh or PC version directly from

Autoregressive product of multi-frame predictions can improve the accuracy of hybrid models

Using SAM Central With iread

Calibration of Confidence Measures in Speech Recognition

Semi-supervised methods of text processing, and an application to medical concept extraction. Yacine Jernite Text-as-Data series September 17.

Modeling function word errors in DNN-HMM based LVCSR systems

Rule Learning with Negation: Issues Regarding Effectiveness

Learning Microsoft Publisher , (Weixel et al)

Evaluation of Usage Patterns for Web-based Educational Systems using Web Mining

Evaluation of Usage Patterns for Web-based Educational Systems using Web Mining

Computer Science is more important than Calculus: The challenge of living up to our potential

Student User s Guide to the Project Integration Management Simulation. Based on the PMBOK Guide - 5 th edition

Zotero: A Tool for Constructionist Learning in Critical Information Literacy

Interpreting ACER Test Results

Cultivating DNN Diversity for Large Scale Video Labelling

Session Six: Software Evaluation Rubric Collaborators: Susan Ferdon and Steve Poast

Moodle Student User Guide

Knowledge Transfer in Deep Convolutional Neural Nets

PowerTeacher Gradebook User Guide PowerSchool Student Information System

Spring 2015 Achievement Grades 3 to 8 Social Studies and End of Course U.S. History Parent/Teacher Guide to Online Field Test Electronic Practice

Seminar - Organic Computing

Unsupervised Learning of Word Semantic Embedding using the Deep Structured Semantic Model

Moodle 2 Assignments. LATTC Faculty Technology Training Tutorial

TRANSFER LEARNING OF WEAKLY LABELLED AUDIO. Aleksandr Diment, Tuomas Virtanen

HIERARCHICAL DEEP LEARNING ARCHITECTURE FOR 10K OBJECTS CLASSIFICATION

Laboratorio di Intelligenza Artificiale e Robotica

Indian Institute of Technology, Kanpur

arxiv:submit/ [cs.cv] 2 Aug 2017

Online ICT Training Courseware

Machine Learning from Garden Path Sentences: The Application of Computational Linguistics

LEGO MINDSTORMS Education EV3 Coding Activities

QuickStroke: An Incremental On-line Chinese Handwriting Recognition System

THE enormous growth of unstructured data, including

Test Administrator User Guide

WiggleWorks Software Manual PDF0049 (PDF) Houghton Mifflin Harcourt Publishing Company

ABC of Programming Linda

Dialog-based Language Learning

Multi-tasks Deep Learning Model for classifying MRI images of AD/MCI Patients

CLASSIFICATION OF TEXT DOCUMENTS USING INTEGER REPRESENTATION AND REGRESSION: AN INTEGRATED APPROACH

An Introductory Blackboard (elearn) Guide For Parents

COMPUTER-ASSISTED INDEPENDENT STUDY IN MULTIVARIATE CALCULUS

Top US Tech Talent for the Top China Tech Company

content First Introductory book to cover CAPM First to differentiate expected and required returns First to discuss the intrinsic value of stocks

Introduction to Ensemble Learning Featuring Successes in the Netflix Prize Competition

EVERYTHING DiSC WORKPLACE LEADER S GUIDE

EDCI 699 Statistics: Content, Process, Application COURSE SYLLABUS: SPRING 2016

Custom Program Title. Leader s Guide. Understanding Other Styles. Discovering Your DiSC Style. Building More Effective Relationships

Applications of data mining algorithms to analysis of medical data

Assignment 1: Predicting Amazon Review Ratings

Essentials of Ability Testing. Joni Lakin Assistant Professor Educational Foundations, Leadership, and Technology

A Latent Semantic Model with Convolutional-Pooling Structure for Information Retrieval

Forget catastrophic forgetting: AI that learns after deployment

A faculty approach -learning tools. Audio Tools Tutorial and Presentation software Video Tools Authoring tools

The Creation and Significance of Study Resources intheformofvideos

STUDENT MOODLE ORIENTATION

TIMSS ADVANCED 2015 USER GUIDE FOR THE INTERNATIONAL DATABASE. Pierre Foy

Attributed Social Network Embedding

SECTION 12 E-Learning (CBT) Delivery Module

Australian Journal of Basic and Applied Sciences

A deep architecture for non-projective dependency parsing

Speak Up 2012 Grades 9 12

Transcription:

CSc-215 (Gordon) Week 10B notes TensorFlow APIs for Image Classification TensorFlow is a powerful open-source library for Deep Learning, developed at Google. It became available to the general public in late 2015, and includes such features as: common neural network elements such as backpropagation, convolutional layers, ReLU, softmax, etc. utilization of GPU for high-speed processing. visualization tools for monitoring learning progress. support for a variety of languages such as Python, C++, Java, and Rust. TensorFlow has already enjoyed widespread use in a variety of machine learning applications such as image recognition, real-time OCR and translation, face-tagging (Facebook), self-driving cars, voice recognition, computers learning to play video games, cancer detection, sentiment analysis, etc. TensorFlow programming involves the definition and use of tensors, which can be thought of as generalized vectors or matrices. Since most computational effort in neural networks involves large numbers of matrix operations (such as dot products), TensorFlow is designed to enable specifying a wide variety of programmerdefined paths through layers of matrix operations. The learning curve on raw TensorFlow coding is a bit steep. As such, a number of high-level APIs have been developed to facilitate using Tensorflow in common scenarios. Also, several existing machine learning APIs have been integrated to also work with Tensorflow. So, there is a wide array of options for those wanting to use Tensorflow. Three widely-used APIs are: Keras TFLearn TFSlim This document describes setting up TFLearn to learn an image classification task. Installing Tensorflow and TFLearn Complete instructions for installing Python and TensorFlow on a number of operating systems can be found on the TensorFlow website: https://www.tensorflow.org/install/ This handout will assume the use of Python 3.6 and Tensorflow 1.3 on Windows. You may (or may not) need to add TensorFlow to your PYTHONPATH. If you do, you ll need to find where TensorFlow is installed on your machine. On my Windows laptop, I added the following to my PYTHONPATH:.;C:\Users\gordonvs\AppData\Local\Programs\Python\Python36\Lib\site-packages\tensorflow After installing TensorFlow, it is recommended to test it using the MNIST dataset, as described in the first two or three getting started tutorials on the TensorFlow website: https://www.tensorflow.org/get_started/ MNIST is a huge database containing the digits 0-9 handwritten in thousands of different ways. MNIST is often used to demonstrate/test an algorithm s ability to learn to recognize handwritten characters. Installing TFLearn is really easy if you have already installed Python and Tensorflow, especially if your Python installation includes pip : pip install tflearn Complete installation instructions, and other TFLearn details, are on the TFLearn website: http://tflearn.org/ This TFLearn walkthrough assumes that the reader understands the previous notes 11A that describe convolutional neural networks. It is also advised to watch this Andrej Karpathy (Stanford/Tesla) lecture: https://www.youtube.com/watch?v=gygynspv230

The Task --- Our goal in this example is to teach a convolutional neural network to differentiate between fishes and horses. In particular, we want to be able to show the network a picture, and have it correctly tell us whether that is a picture of a fish or a horse. Our steps are as follows: 1. collect images to serve as training data, and additional images to serves as validation (testing) data. 2. prepare/standardize the images so they can be used to train (and test) a CNN. 3. prepare a TFLearn Python program to learn our training data. 4. run the training program, which causes TensorFlow to build and train a CNN on our training data. 5. prepare a TFLearn Python program to test our trained network. 6. run the testing program, which causes TensorFlow to report on the network s ability to generalize. (additional) use TensorBoard to visualize the progress of learning, either during or after training. Step 1 collecting images Since we will be using supervised learning, we need training data. For this task, that means obtaining lots of JPG images of fishes, and lots of JPG images of horses. Most of these images will be used as training data, but we will also set some of them aside for use as testing data. In this example, 24 pictures of fishes and 24 pictures of horses were downloaded from Google Images. They were of various resolutions and aspect ratios. Some examples looked like this: 40 images will be used for training (20 fishes, 20 horses), and 8 will be used for testing (4 fishes, 4 horses). Note that this isn t likely to be enough training cases for effective generalization. But it will allow us to demonstrate the steps and the framework. Step 2 Preparing the images for training Convolutional neural networks are generally designed to work with images that are perfectly square, and they all must have the same resolution. There are many tools for doing this. In this example, a web-based tool at www.resizemypicture.com was used, that can resize up to 5 images at once. Using this tool, we converted each of our pictures to 100x100 square images. The four images above then looked like this: The 20 training examples of fish were put in a folder called: train/subfolder_0 The 20 training examples of horses were put in a folder called: train/subfolder_1 The 4 testing examples of fish were put in a folder called: validate/subfolder_0 The 4 testing examples of horses were put in a folder called: validate/subfolder_1

Step 3 Preparing the TFLearn Python training program Suppose we wish to use the following AlexNET-style CNN architecture to learn our training data: color image 100x100x3 2x2 stride 2 3x3 stride 2 2x2 stride 2 fully connected 1024 d 1024 d 2 softmax The following Python program ( deepneuralnet.py ) defines the network and expected input format: import tflearn from tflearn.layers.core import input_data, dropout, fully_connected from tflearn.layers.conv import conv_2d, max_pool_2d from tflearn.layers.estimator import regression from tflearn.metrics import Accuracy acc = Accuracy() network = input_data(shape=[none, 100, 100, 3]) # Conv layers ------------------------------------ # Fully Connected Layers ------------------------- network = fully_connected(network, 1024, activation='tanh') network = dropout(network, 0.5) network = fully_connected(network, 1024, activation='tanh') network = dropout(network, 0.5) network = fully_connected(network, 2, activation='softmax') network = regression(network, optimizer='momentum', loss='categorical_crossentropy', learning_rate=0.001, metric=acc) model = tflearn.dnn(network) The following Python program ( train.py ) reads the training and validation data, and initiates the training: import deepneuralnet as net import numpy as np from tflearn.data_utils import image_preloader model = net.model X, Y = image_preloader(target_path='./train', image_shape=(100, 100), mode='folder', grayscale=false, categorical_labels=true, normalize=true) X = np.reshape(x, (-1, 100, 100, 3)) W, Z = image_preloader(target_path='./validate', image_shape=(100, 100), mode= folder, grayscale=false, categorical_labels=true, normalize=true) W = np.reshape(w, (-1, 100, 100, 3)) model.fit(x, Y, n_epoch=250, validation_set=(w,z), show_metric=true) model.save('./ztrainednet/final-model.tfl')

Step 4 run the training program We run the training program by opening a command window and typing: python train.py As training proceeds, TFLearn gives a progress report similar to the following: Training Step: 1 loss: 0.00000 acc: 0.0000 val_loss: 0.69784 val_acc: 0.5000 Training Step: 2 loss: 0.63188 acc: 0.3937 val_loss: 0.69763 val_acc: 0.5000 Training Step: 3 loss: 0.68900 acc: 0.4551 val_loss: 0.69734 val_acc: 0.5000... Training Step: 248 loss: 0.57213 acc: 0.7379 val_loss: 0.50747 val_acc: 0.7500 Training Step: 249 loss: 0.56288 acc: 0.7391 val_loss: 0.50415 val_acc: 0.8750 Training Step: 250 loss: 0.58919 acc: 0.7058 val_loss: 0.50524 val_acc: 0.7500 We hope that the loss fields (representing the total error) decrease over time. We hope that the acc fields (representing the accuracy) increase over time. The fields marked loss and acc refer to the error and accuracy thus far on the training data. The fields preceded by val_ refer to the aggregate performance thus far on the testing (validation) data. At the conclusion of training, the trained network is stored in./ztrainednet/final-model.tfl Step 5 prepare the TFLearn Python testing program We can now check the performance of the trained network on each of the training cases. The program ( predict.py ) reads the validation (testing) data and tests each one using the trained network: import deepneuralnet as net import numpy as np from tflearn.data_utils import image_preloader model = net.model path_to_model = './ZtrainedNet/final-model.tfl' model.load(path_to_model) X, Y = image_preloader(target_path='./validate', image_shape=(100,100), mode= folder, grayscale=false, categorical_labels=true, normalize=true) X = np.reshape(x, (-1, 100, 100, 3)) for i in range(0, len(x)): iimage = X[i] icateg = Y[i] result = model.predict([iimage])[0] prediction = result.tolist().index(max(result)) reality = icateg.tolist().index(max(icateg)) if prediction == reality: print("image %d CORRECT " % i, end='') else: print("image %d WRONG " % i, end='') print(result) Step 6 run the testing program We run the training program by typing: python predict.py On our testing data images, we get the result shown at the right: The trained network failed to correctly classify two of the fishes. Note that it appears confident in 5 of the 8 test cases. image 0 WRONG [ 0.466 0.534 ] image 1 CORRECT [ 0.545 0.455 ] image 2 WRONG [ 0.493 0.507 ] image 3 CORRECT [ 0.736 0.264 ] image 4 CORRECT [ 0.293 0.707 ] image 5 CORRECT [ 0.359 0.641 ] image 6 CORRECT [ 0.319 0.681 ] image 7 CORRECT [ 0.382 0.618 ]

(additional) using TensorBoard Installing TensorFlow also installs TensorBoard, a graphing tool for visualizing various statistics during (or after) neural network learning. TensorBoard can also be used when using TFLearn. To use TensorBoard, we have to modify the last line in our deepneuralnet.py file as follows. Change the line that says: to: model = tflearn.dnn(network) model = tflearn.dnn(network, tensorboard_verbose=3, tensorboard_dir="logs") This causes TensorFlow to create and maintain a log file during training, in the directory called logs. TensorBoard will use the log information to generate graphs that can be accessed in a browser. To run TensorBoard, you ll need to open a second command window, navigate to the same folder from which you are running the training program, and type: tensorboard logdir=logs This tells tensorboard to use the logs found in the directory called logs specified in the model, above. TensorBoard responds with a message specifying an html address, something like: TensorBoard 0.1.8 at http://mycomp:6006 (Press CTRL+C to quit) TensorBoard is now generating graphs that can be accessed in a browser, using the indicated address: