Deep Learning With PyTorch 2Ed Final – Howard Huang

📥
Total Downloads: 8
 - Unknown book cover

PyTorch allows us to use any computation in our model by subclass- ing nn.Module. In PyTorch, nn.Module is a fundamental building block that can represent both entire networks and individual components within networks. This recursive nature is key to PyTorch’s flexibility—any component (like a convolution layer) is itself an nn.Module, and your complete network is also an nn.Module. To subclass nn.Module, at a minimum we need to define a forward function that takes the inputs to the module and returns the output.

This is where we define our module’s computation. Additionally, with PyTorch, if we use standard torch opera- tions, autograd will take care of the backward pass automatically; and indeed, an nn.Module never comes with a backward since it is implicitly defined. Typically, our computation will use other modules—premade like convolutions or customized. To include these submodules, we typically define them in the construc- tor __init__ and assign them to self for use in the forward function.

They will, at the same time, hold their parameters throughout the lifetime of our module. Note that you need to call super().__init__() before you can do that (or PyTorch will remind you). 8.3.1 Our network as an nn.Module Let’s write our network as a subclass of nn.Module. To create our network, we’ll instan- tiate all the individual layer modules (nn.Conv2d, nn.Linear, etc.) in the constructor and then specify how data flows through these modules in the forward method: # In[27]: class Net(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(3, 16, kernel_size=3, padding=1) self.act1 = nn.Tanh() self.pool1 = nn.MaxPool2d(2) self.conv2 = nn.Conv2d(16, 8, kernel_size=3, padding=1) self.act2 = nn.Tanh() self.pool2 = nn.MaxPool2d(2) self.fc1 = nn.Linear(8 * 8 * 8, 32) self.act3 = nn.Tanh() self.fc2 = nn.Linear(32, 2) def forward(self, x): out = self.pool1(self.act1(self.conv1(x))) out = self.pool2(self.act2(self.conv2(out))) out = out.view(-1, 8 * 8 * 8) out = self.act3(self.fc1(out)) out = self.fc2(out) return out This reshape is what we were missing earlier.

8.3 Subclassing nn.Module The Net class is equivalent to the nn.Sequential model we built earlier in terms of sub- modules, but by writing the forward function explicitly, we can manipulate the output of self.pool2 directly and call view on it to turn it into a B × N vector.

An end-to-end machine learning pipeline from data to training to production Praise for the first edition With this publication, we finally have a definitive treatise on PyTorch. It covers the basics and abstractions in great detail. —From the Foreword by Soumith Chintala, Cocreator of PyTorch Deep learning divided into digestible chunks with code samples that build up logically. —Mathieu Zhang, NVIDIA Timely, practical, and thorough.

Don’t put it on your bookshelf but next to your laptop. —Philippe Van Bergen, P2 Consulting Deep Learning with PyTorch offers a very pragmatic overview of deep learning. It is a didactical resource. —Orlando Alejo Mendez Morales, Experian Deep Learning with PyTorch SECOND EDITION TRAINING AND APPLYING DEEP LEARNING AND GENERATIVE AI MODELS HOWARD HUANG LUCA ANTIGA ELI STEVENS THOMAS VIEHMANN M A N N I N G SHELTER ISLAND For online information and ordering of this and other Manning books, please visit www.manning.com.

The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2026 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.

Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end.

Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. The authors and publisher have made every effort to ensure that the information in this book was correct at press time. The authors and publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause, or from any usage of the information herein.

Manning Publications Co.

This is a short excerpt from the opening of “” by Unknown, quoted for review and introduction purposes. All rights belong to the copyright holders.

Book Information

  • Unique ID: 9530947a80da4c44
  • File Extension: .pdf
  • File Size: 30,797,991 bytes (29.371 MB)
  • Title:
  • Author: Unknown
  • ISBN: 9781633438859
  • Pages: 547
  • Language: English (en)

Reading & Word Statistics

  • Estimated Reading Time: 865.15 minutes
  • Total Words: 173,030
  • Total Characters: 1,096,467
  • Average Words per Page: 316.33
  • Average Characters per Page: 2004.51

Most Frequent Words

model (1699), data (1269), training (921), loss (771), tensor (694), torch (678), pytorch (597), chapter (568), image (536), using (509), figure (463), use (461), models (452), learning (437), output (429), input (429), self (426), size (418), dataset (359), linear (340), network (333), one (326), batch (313), like (313), need (304), we’ll (304), function (296), first (284), parameters (281), process (280), time (276), points (276), tensors (268), images (260), see (260), set (255), deep (252), also (250), epoch (250), get (243), train (243), code (238), values (235), neural (235), weights (226), let’s (225), now (221), example (221), we’re (202), step (202), samples (200), used (199), metrics (199), new (198), different (197), number (195), text (194), module (194), it’s (193), between (193), two (186), sample (176), python (176), validation (175), make (173), work (171), forward (170), part (168), device (168), shape (166), want (165), since (165), val (165), list (162), take (161), class (160), classification (160), true (160), optimizer (158), conv (157), way (156), loop (154), index (151), run (150), def (150), point (148), correct (147), multiple (145), value (141), grad (141), inputs (140), layer (140), single (139), https (138), segmentation (138), well (137), networks (136), parallelism (136), recall (134), results (134).

PDF Download

📖 Read Online (3D Flipbook)

You can start reading by flipping the pages.

Or download it as a PDF: