Hands-On One-shot Learning with Python - Shruti Jadon - E-Book

Hands-On One-shot Learning with Python E-Book

Shruti Jadon

0,0
36,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Get to grips with building powerful deep learning models using PyTorch and scikit-learn




Key Features



  • Learn how you can speed up the deep learning process with one-shot learning


  • Use Python and PyTorch to build state-of-the-art one-shot learning models


  • Explore architectures such as Siamese networks, memory-augmented neural networks, model-agnostic meta-learning, and discriminative k-shot learning



Book Description



One-shot learning has been an active field of research for scientists trying to develop a cognitive machine that mimics human learning. With this book, you'll explore key approaches to one-shot learning, such as metrics-based, model-based, and optimization-based techniques, all with the help of practical examples.






Hands-On One-shot Learning with Python will guide you through the exploration and design of deep learning models that can obtain information about an object from one or just a few training samples. The book begins with an overview of deep learning and one-shot learning and then introduces you to the different methods you can use to achieve it, such as deep learning architectures and probabilistic models. Once you've got to grips with the core principles, you'll explore real-world examples and implementations of one-shot learning using PyTorch 1.x on datasets such as Omniglot and MiniImageNet. Finally, you'll explore generative modeling-based methods and discover the key considerations for building systems that exhibit human-level intelligence.






By the end of this book, you'll be well-versed with the different one- and few-shot learning methods and be able to use them to build your own deep learning models.




What you will learn



  • Get to grips with the fundamental concepts of one- and few-shot learning


  • Work with different deep learning architectures for one-shot learning


  • Understand when to use one-shot and transfer learning, respectively


  • Study the Bayesian network approach for one-shot learning


  • Implement one-shot learning approaches based on metrics, models, and optimization in PyTorch


  • Discover different optimization algorithms that help to improve accuracy even with smaller volumes of data


  • Explore various one-shot learning architectures based on classification and regression



Who this book is for



If you're an AI researcher or a machine learning or deep learning expert looking to explore one-shot learning, this book is for you. It will help you get started with implementing various one-shot techniques to train models faster. Some Python programming experience is necessary to understand the concepts covered in this book.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 147

Veröffentlichungsjahr: 2020

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Hands-On One-shot Learning with Python
Learn to implement fast and accurate deep learning models with fewer training samples using PyTorch

 

 

 

 

 

 

 

Shruti Jadon 
Ankush Garg

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Hands-On One-shot Learning with Python

Copyright © 2019 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

 

Commissioning Editor:Amey VarangaonkarAcquisition Editor:Yogesh DeokarContent Development Editor:Athikho Sapuni RishanaSenior Editor: Sofi RogersTechnical Editor: Manikandan KurupCopy Editor: Safis EditingProject Coordinator: Aishwarya MohanProofreader: Safis EditingIndexer: Priyanka DhadkeProduction Designer: Jyoti Chauhan

First published: April 2020

Production reference: 1090420

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-83882-546-1

www.packtpub.com

 

Packt.com

Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Fully searchable for easy access to vital information

Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

About the authors

Shruti Jadon is currently working as a Machine Learning Software Engineer at Juniper Networks, Sunnyvale and visiting Researcher at Rhode Island Hospital (Brown University). She has obtained her master's degree in Computer Science from University of Massachusetts, Amherst. Her research interests include deep learning architectures, computer vision, and convex optimization. In the past, she has worked at Autodesk, Quantiphi, SAP Labs, and Snapdeal.

 

Ankush Garg is currently working as a Software Engineer in the auto-translation team at Google, Mountain View. He has obtained his master's degree in Computer Science from the University of Massachusetts, Amherst, and his bachelor's at NSIT, Delhi. His research interests include language modeling, model compression, and optimization. In the past, he has worked as a Software Engineer at Amazon, India.

About the reviewer

Greg Walters has been involved with computers and computer programming since 1972. He is well versed in Visual Basic, Visual Basic.NET, Python, and SQL, and is an accomplished user of MySQL, SQLite, Microsoft SQL Server, Oracle, C++, Delphi, Modula-2, Pascal, C, 80x86 Assembler, COBOL, and Fortran. He is a programming trainer and has trained numerous individuals in many pieces of computer software, including MySQL, Open Database Connectivity, Quattro Pro, Corel Draw!, Paradox, Microsoft Word, Excel, DOS, Windows 3.11, Windows for Workgroups, Windows 95, Windows NT, Windows 2000, Windows XP, and Linux. He is currently retired and, in his spare time, is a musician and loves to cook. He is also open to working as a freelancer on various projects.

 

 

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Hands-On One-shot Learning with Python

About Packt

Why subscribe?

Contributors

About the authors

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Section 1: One-shot Learning Introduction

Introduction to One-shot Learning

Technical requirements

The human brain – overview

How the human brain learns

Comparing human neurons and artificial neurons

Machine learning – historical overview

Challenges in machine learning and deep learning

One-shot learning – overview

Prerequisites of one-shot learning

Types of one-shot learning

Setting up your environment

Coding exercise

kNN – basic one-shot learning

Summary

Questions

Section 2: Deep Learning Architectures

Metrics-Based Methods

Technical requirements

Parametric methods – an overview

Neural networks – learning procedure

Visualizing parameters

Understanding Siamese networks

Architecture

Preprocessing

Contrastive loss function

Triplet loss function

Applications

Understanding matching networks

Model architecture

Training procedure

Modeling level – the matching networks architecture

Coding exercise

Siamese networks – the MNIST dataset

Matching networks – the Omniglot dataset

Summary

Questions

Further reading

Model-Based Methods

Technical requirements

Understanding Neural Turing Machines

Architecture of an NTM

Modeling 

Reading 

Writing

Addressing

Memory-augmented neural networks

Reading

Writing

Understanding meta networks

Algorithm of meta networks

Algorithm

Coding exercises

Implementation of NTM

Implementation of MAAN

Summary

Questions

Further reading

Optimization-Based Methods

Technical requirements

Overview of gradient descent

Understanding model-agnostic meta-learning

Understanding the logic behind MAML

Algorithm

MAML application – domain-adaptive meta-learning

Understanding LSTM meta-learner

Architecture of the LSTM meta-learner

Data preprocessing

Algorithm – pseudocode implementation

Exercises

A simple implementation of model-agnostic meta-learning

A simple implementation of domain-adaption meta-learning

Summary

Questions

Further reading

Section 3: Other Methods and Conclusion

Generative Modeling-Based Methods

Technical requirements

Overview of Bayesian learning

Understanding directed graphical models

Overview of probabilistic methods

Bayesian program learning

Model

Type generation

Token generation

Image generation

Discriminative k-shot learning

Representational learning

Probabilistic model of the weights

Choosing a model for the weights

Computation and approximation for each phase 

Phase 1 – representation learning

Phase 2 – concept learning

Phase 3 – k-shot learning

Phase 4 – k-shot testing

Summary

Further reading

Conclusions and Other Approaches

Recent advancements

Object detection in few-shot domains

Image segmentation in few-shot domains

Related fields

Semi-supervised learning

Imbalanced learning 

Meta-learning

Transfer learning

Applications

Further reading

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

One-shot learning has been an active field of research for many scientists who are trying to find a cognitive machine that is as close to human beings as possible in terms of learning. As there are various theories as to how humans effect one-shot learning, there are a variety of different methods available to achieve this, ranging from non-parametric models and deep learning architectures to probabilistic models.

Hands-On One-shot Learning with Python will focus on designing and learning about models that can learn information relating to an object from one, or only a few, training examples. The book will begin by giving you a brief overview of deep learning and one-shot learning to get you started. Then, you will learn different methods to achieve this, including non-parametric models, deep learning architectures, and probabilistic models. Once you are well versed in the core principles, you will explore some of the practical real-world examples and implementations of one-shot learning using scikit-learn and PyTorch.

By the end of the book, you will be familiar with one-shot and few-shots learning methods and be able to accelerate your deep learning processes with one-shot learning.

Who this book is for

AI researchers, as well as machine learning and deep learning experts who wish to apply one-shot learning to reduce the overall training time of their models, will find this book to be a very good introductory source of learning. 

What this book covers

Chapter 1, Introduction to One-shot Learning, tells us what one-shot learning is and how it works. It also tells us about the human brain's workings and how it translates to machine learning.

Chapter 2, Metrics-Based Methods, explores methods that use different forms of embeddings, and evaluation metrics, by keeping the core as basic k-nearest neighbors.

Chapter 3, Model-Based Methods, explores two architectures whose internal architectures help to train a k-shot learning model.

Chapter 4, Optimization-Based Methods, explores different forms of optimization algorithms, which help in improving accuracy even when the volume of data is low.

Chapter 5, Generative Modeling-Based Methods, explores the development of a Bayesian learning framework based on representing object categories with probabilistic models.

Chapter 6, Conclusions and Other Approaches, goes through certain aspects of architecture, metrics, and algorithms to understand how we can determine whether an approach is close to human brain capability.

To get the most out of this book

Knowledge of basic machine learning and deep learning concepts and the underlying math, as well as some exposure to Python programming, will be required for this book.

Software/Hardware covered in this book

OS requirements

Software: Jupyter Notebook, Anaconda

Language and Libraries: Python 3.X and above, PyTorch 1.4, Scikit-learn.

Any OS (Linux environment is preferable).

Hardware: None. But if you wish to increase the speed of training. You can use the same codes with minor modifications on GPU Hardware.

 

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-One-shot-Learning-with-Python. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781838825461_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Import the iris dataset."

A block of code is set as follows:

# import small dataset

iris

datasets

.

load_iris

()

X

iris

.

data

y

iris

.

target

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[2 1 2 1 2 0 1 0 0 0 2 1 1 0 0 0 2 2 1 2 1 0 0 1 2 0 0 2 0 0]

Any command-line input or output is written as follows:

pip install -r requirements.txt

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "We can use a new loss function known as triplet loss, which helps the architecture to get better results."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Section 1: One-shot Learning Introduction

Deep learning has brought about a major change to industry—be it manufacturing, medical, or human resources. With this major revolution and proof of concept, almost every industry is trying to adapt its business model to comply with deep learning, but it has some major requirements that may not fit every business or industry. After reading this section, you will have a proper understanding of the pros and cons of deep learning.

This section comprises the following chapter:

Chapter 1

Introduction to One-shot Learning

Introduction to One-shot Learning

Humans can learn new things with a small set of examples. When presented with stimuli, humans seem to be able to understand new concepts quickly and then recognize variations of those concepts in the future. A child can learn to recognize a dog from a single picture, but a machine learning system needs a lot of examples to learn the features of a dog and recognize them in the future. Machine learning, as a field, has been highly successful at a variety of tasks, such as classification and web searching, as well as image and speech recognition. Often, however, these models do not perform well without a large amount of data (examples) to learn from. The primary motivation behind this book is to train a model with very few examples that is capable of generalizing to unfamiliar categories without extensive retraining.

Deep learning has played an important role in the advancement of machine learning, but it also requires large datasets. Different techniques, such as regularization, can reduce overfitting in low-data regimes, but do not solve the inherent problem that comes with fewer training examples. Furthermore, the large size of datasets leads to slow learning, requiring many weight updates using gradient descent. This is mostly due to the parametric aspect of an ML algorithm, in which training examples need to be slowly learned. In contrast, many known non-parametric models such as nearest neighbor do not require any training, but performance depends on a sometimes arbitrarily chosen distance metric such as the L2 distance. One-shot learning is an object categorization problem in computer vision. While most ML-based object categorization algorithms require hundreds or thousands of images and very large datasets to train on, one-shot learning aims to learn information about object categories from one, or only a few, training images. In this chapter, we will learn about the basics of one-shot learning and explore its real-world applications. 

The following topics will be covered in this chapter:

The human brain—overview

Machine learning—history overview

One-shot learning—overview

Setting up your environment

Coding exercise