Deep Learning with MXNet Cookbook - Andrés P. Torres - E-Book

Deep Learning with MXNet Cookbook E-Book

Andrés P. Torres

0,0
35,99 €

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

Mehr erfahren.
Beschreibung

Explore the capabilities of the open-source deep learning framework MXNet to train and deploy neural network models and implement state-of-the-art (SOTA) architectures in Computer Vision, natural language processing, and more. The Deep Learning with MXNet Cookbook is your gateway to constructing fast and scalable deep learning solutions using Apache MXNet.
Starting with the different versions of MXNet, this book helps you choose the optimal version for your use and install your library. You’ll work with MXNet/Gluon libraries to solve classification and regression problems and gain insights into their inner workings. Venturing further, you’ll use MXNet to analyze toy datasets in the areas of numerical regression, data classification, picture classification, and text classification. From building and training deep-learning neural network architectures from scratch to delving into advanced concepts such as transfer learning, this book covers it all. You'll master the construction and deployment of neural network architectures, including CNN, RNN, LSTMs, and Transformers, and integrate these models into your applications.
By the end of this deep learning book, you’ll wield the MXNet and Gluon libraries to expertly create and train deep learning networks using GPUs and deploy them in different environments.

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

EPUB

Veröffentlichungsjahr: 2023

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.



Deep Learning with MXNet Cookbook

Discover an extensive collection of recipes for creating and implementing AI models on MXNet

Andrés P. Torres

Andrés P. Torres

BIRMINGHAM—MUMBAI

Deep Learning with MXNet Cookbook

Copyright © 2023 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 author, 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.

Group Product Manager: Ali Abidi

Publishing Product Manager: Sunith Shetty

Content Development Editor: Priyanka Soam

Technical Editor: Kavyashree K S

Copy Editor: Safis Editing

Project Coordinator: Shambhavi Mishra

Proofreader: Safis Editing

Indexer: Hemangini Bari

Production Designer: Ponraj Dhandapani

Marketing Coordinator: Vinishka Kalra

First published: Dec 2023

Production reference: 2201223

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK.

ISBN 978-1-80056-960-7

www.packtpub.com

To my parents, thanks for giving me everything. To my sister Carmen and her family, for reminding me that life is not only work, above all Carlos, Adriana and Pablo, I love you madly.

I miss Madrid because of you all, but also because of my friends from there, Almu, Alba, Bea, @nosinmiscascos, Ducali, Cala, Rubens, Marco, Moi, Agus, Charlie, Puente, Johnny, Surcio, Chemo and Zaragoza, because I would like to see them so much more, and when I see them the cliché is true, it’s indeed as if time hadn’t passed. Specially, the last three, because you have supported me greatly with my latest changes and this book. To new friends, Julien, Santi, Paul, Laz, Ricciardo (and partners!), Karla, Carmen, Marina, Michele, Luis and Carlos. Without you, I wouldn’t have adapted to the UK. Same with Valentina and Javi, thanks for those board game nights!. Biggest hug to the last three for their recent changes, we are all a team, and we are all with you in this.

Lastly, to Marta, thank you for always supporting me whatever my mood.

- Andrés P. Torres

Foreword

The best teachers speak from experience. The best teachers remember the learning journey they themselves undertook. The best teachers end up teaching the best topics from a perspective given by a profound understanding of the foundations.

This is nowhere more true than you can find here in this book. Andrés P. Torres has a wealth of practical hands-on experience in machine learning, built and enabled by his detailed and nuanced understanding of the fundamentals of the subject.

He has built it, he has deployed it, he has iterated and he has, like all the best seasoned practitioners, built an atlas on how to approach a flotilla of ML problems and challenges.

This book is a direct consequence of the author’s professional journey, one that I have been privileged to share in as a colleague. It draws on his time at Amazon and his wider career to provide a compact, accessible and appropriately detailed practitioners guide to MXNet - a deep learning framework which is used widely in commercial and research.

If you are new to the MXNet framework or finding yourself in charge of maintaining and developing a code base built with MXNet then this book is, of course, for you. But more generally, this book allows any deep learning practitioner to gain deep insight into the foundations of techniques that transcend any particular framework. Indeed, understanding how several frameworks approach common aspects and problems of deep learning is a powerful way to understand concepts beyond and below any given API.

This book is full of worked examples which are carefully chosen to balance the common-case problems and topics you are likely to face, be appropriately pedagogical and also provide multiple jumping off points into the wider MXNet documentation and code base. You will enjoy it. Who is not deeply entertained by learning how to teach machines to learn (deeply) ?

Prof. Paul Newman CBE FREng FIEEE FIET

BP Chair of Information Engineering

University of Oxford, Oxford

CTO Oxa Autonomy

Contributors

About the author

Andrés P. Torres, is the Head of Perception at Oxa, a global leader in industrial autonomous vehicles, leading the design and development of State-Of The-Art algorithms for autonomous driving. Before, Andrés had a stint as an advisor and Head of AI at an early stage content generation startup, Maekersuite, where he developed several AI-based algorithms for mobile phones and the web. Prior to this, Andrés was a Software Development Manager at Amazon Prime Air, developing software to optimize operations for autonomous drones.

I want to specially thank Marta M. Civera for most of the illustrations in Chapter 5, another example of her wonderful skills, apart from being a fantastic Architect and, above all, partner.

About the reviewers

Tuhin Sharma is Sr. Principal Data Scientist at Redhat in the Corporate Development and Strategy group. Prior to that, he worked at Hypersonix as an AI Architect. He also co-founded and has been CEO of Binaize, a website conversion intelligence product for eCommerce SMBs. He received a master’s degree from IIT Roorkee and a bachelor’s degree from IIEST Shibpur in Computer Science. He loves to code and collaborate on open-source and research projects. He has 4 research papers and 5 patents in the field of AI and NLP. He is a reviewer of the IEEE MASS conference in the AI track. He writes deep learning articles for O’Reilly in collaboration with the AWS MXNET team. He is a regular speaker at prominent AI conferences like O’Reilly AI, ODSC, GIDS, etc.

Anshu Trivedi, as a data scientist at BharatPe with three years plus of experience, delves into the realms of data engineering while mentoring budding data science enthusiasts at Newton School. Alongside, She actively contributes to open-source projects and regularly shares technical insights through her blog. Her passion lies in exploring intricate concepts of Artificial Intelligence and disseminating knowledge to foster learning and innovation.

Table of Contents

Preface

1

Up and Running with MXNet

Technical requirements

Installing MXNet, Gluon, GluonCV, and GluonNLP

Getting ready

How to do it...

How it works...

There’s more…

NumPy and MXNet ND arrays

Getting ready

How to do it...

How it works...

There’s more…

2

Working with MXNet and Visualizing Datasets – Gluon and DataLoader

Technical requirements

Understanding regression datasets – loading, managing, and visualizing the House Sales dataset

Getting ready

How to do it...

How it works...

There’s more…

Understanding classification datasets – loading, managing, and visualizing the Iris dataset

Getting ready

How to do it...

How it works...

There’s more…

Understanding image datasets – loading, managing, and visualizing the Fashion-MNIST dataset

Getting ready

How to do it...

How it works...

There’s more…

Understanding text datasets – loading, managing, and visualizing the Enron Email dataset

Getting ready

How to do it...

How it works...

There’s more…

3

Solving Regression Problems

Technical requirements

Understanding the math of regression models

Getting ready

How to do it...

How it works...

There’s more…

Defining loss functions and evaluation metrics for regression

Getting ready

How to do it...

How it works...

There’s more...

Training regression models

Getting ready

How to do it...

How it works...

There’s more...

Evaluating regression models

Getting ready

How to do it...

How it works...

There’s more...

4

Solving Classification Problems

Technical requirements

Understanding math for classification models

Getting ready

How to do it...

How it works...

There’s more…

Defining loss functions and evaluation metrics for classification

Getting ready

How to do it...

How it works...

There’s more...

Training for classification models

Getting ready

How to do it...

How it works...

There’s more...

Evaluating classification models

Getting ready

How to do it...

How it works...

There’s more...

5

Analyzing Images with Computer Vision

Technical requirements

Understanding convolutional neural networks

Getting ready

How to do it...

How it works…

There’s more...

Classifying images with MXNet – GluonCV Model Zoo, AlexNet, and ResNet

Getting ready

How to do it...

How it works...

There’s more...

Detecting objects with MXNet – Faster R-CNN and YOLO

Getting ready

How to do it...

How it works...

There’s more...

Segmenting objects in images with MXNet – PSPNet and DeepLab-v3

Getting ready

How to do it...

How it works...

There’s more...

6

Understanding Text with Natural Language Processing

Technical requirements

Introducing NLP networks

Getting ready

How to do it...

Introducing Recurrent Neural Networks (RNNs)

Improving RNNs with Long Short-Term Memory (LSTM)

Introducing GluonNLP Model Zoo

Paying attention with Transformers

How it works...

There’s more...

Classifying news highlights with topic modeling

Getting ready

How to do it...

How it works...

There’s more...

Analyzing sentiment in movie reviews

Getting ready

How to do it...

How it works...

There’s more...

Translating text from Vietnamese to English

Getting ready

How to do it...

How it works...

There’s more...

7

Optimizing Models with Transfer Learning and Fine-Tuning

Technical requirements

Understanding transfer learning and fine-tuning

Getting ready

How to do it...

How it works…

There’s more...

Improving performance for classifying images

Getting ready

How to do it...

Revisiting the ImageNet-1k and Dogs vs Cats datasets

How it works…

There’s more...

Improving performance for segmenting images

Getting ready

How to do it...

How it works…

There’s more...

Improving performance for translating English to German

Getting ready

How to do it...

How it works…

There’s more...

8

Improving Training Performance with MXNet

Technical requirements

Introducing training optimization features

Getting ready

How to do it...

How it works...

There’s more…

Optimizing training for image segmentation

Getting ready

How to do it...

How it works...

There’s more…

Optimizing training for translating text from English to German

Getting ready

How to do it...

How it works...

There’s more…

9

Improving Inference Performance with MXNet

Technical requirements

Introducing inference optimization features

Getting ready

How to do it...

How it works...

There’s more…

Optimizing inference for image segmentation

Getting ready

How to do it...

How it works...

There’s more…

Optimizing inference when translating text from English to German

Getting ready

How to do it...

How it works...

There’s more…

Index

Other Books You May Enjoy

2

Working with MXNet and Visualizing Datasets – Gluon and DataLoader

In the previous chapter, we learned how to set up MXNet. We also verified how MXNet could leverage our hardware to provide maximum performance. Before applying deep learning (DL) to solve specific problems, we need to understand how to load, manage, and visualize the datasets we will be working with. In this chapter, we will start using MXNet to analyze some toy datasets in the domains of numerical regression, data classification, image classification, and text classification. To manage those tasks efficiently, we will see new MXNet libraries and functions such as Gluon (an API for DL) and DataLoader.

In this chapter, we will cover the following topics:

Understanding regression datasets – loading, managing, and visualizing the House Sales datasetUnderstanding classification datasets – loading, managing, and visualizing the Iris datasetUnderstanding image datasets – loading, managing, and visualizing the Fashion-MNIST datasetUnderstanding text datasets – loading, managing, and visualizing the Enron Email dataset

Technical requirements

Apart from the technical requirements specified in the Preface, no other requirements apply to this chapter.

The code for this chapter can be found at the following GitHub URL: https://github.com/PacktPublishing/Deep-Learning-with-MXNet-Cookbook/tree/main/ch02

Furthermore, you can directly access each recipe from Google Colab; for example, for the first recipe of this chapter, visit https://colab.research.google.com/github/PacktPublishing/Deep-Learning-with-MXNet-Cookbook/blob/main/ch02/2_1_Toy_Dataset_for_Regression_Load_Manage_and_Visualize_House_Sales_Dataset.ipynb.

Understanding regression datasets – loading, managing, and visualizing the House Sales dataset

The training process of machine learning (ML) models can be divided into three main sub-groups:

Supervised learning (SL): The expected outputs are known for at least some dataUnsupervised learning (UL): The expected outputs are not known but the data has some features that could help with understanding its internal distributionReinforcement learning (RL): An agent explores the environment and makes decisions based on the inputs acquired from the environment

There is also an approach that falls in between the first two sub-groups called weakly SL, where there are not enough known outputs to follow an SL approach for one of the following reasons:

The outputs are inaccurateOnly some of the output features are known (incomplete)They are not exactly the expected outputs but are connected/related to the task we intend to achieve (inexact)

With SL, one of the most common problem types is regression. In regression problems, we want to estimate numerical outputs given a variable number of input features. In this recipe, we will analyze a toy regression dataset from Kaggle: House Sales in King County, USA.

The House Sales dataset presents the problem of estimating the price of a house (in $) given the following19 features:

Date of the home saleNumberofbedroomsNumberofbathrooms, where 0.5 accounts for a room with a toilet but no showerSqft_living: Square feet of the apartment’s interior living spaceSqft_lot: Square feet of the land spaceNumberoffloorsWaterfront view or notAn index from 0 to 4 of how good the view of the property isAn index from 1 to 5 on the condition of the apartmentGrade: An index from 1 to 13, with 1 being the worst and 13 the bestSqft_above: Square feet of the interior housing space that is above ground levelSqft_basement: Square feet of the interior housing space that is below ground levelYr_built: The year the house was initially builtYr_renovated: The year of the house’s last renovationZipcode area the house is inLatitude (Lat)Longitude (Long)Sqft_living15: Square feet of interior housing living space for the nearest 15 neighborsSqft_lot15: Square feet of the land lots of the nearest 15 neighbors

These data features are provided for 21,613 houses along with the price (value to be estimated).

Getting ready

The following dataset is provided under the CC0 Public Domain license and can be downloaded from https://www.kaggle.com/harlfoxem/housesalesprediction.

To read the data, we are going to use a very well-known library to manage data, pandas, and we will use the most common data structure for the library, DataFrames. Moreover, in order to plot the data and several visualizations we will compute, we will use the matplotlib, pyplot, and seaborn libraries. Therefore, we must run the following code:

import matplotlib.pyplot as plt import pandas as pd import seaborn as sns

If you do not have these libraries installed, they can be easily installed with the following terminal commands:

!pip3 install matplotlib==3.7.1 !pip3 install pandas==1.5.3 !pip3 install seaborn==0.12.2