Custom layers
In the previous section, we briefly mentioned the nn.Module
class as a base parent for all NN building blocks exposed by PyTorch. It's not only a unifying parent for the existing layers—it's much more than that. By subclassing the nn.Module
class, you can create your own building blocks which can be stacked together, reused later, and integrated into the PyTorch framework flawlessly.
At its core, nn.Module
provides quite rich functionality to its children:
- It tracks all submodules that the current module includes. For example, your building block can have two feed-forward layers used somehow to perform the block's transformation.
- It provides functions to deal with all parameters of the registered submodules. You can obtain a full list ...
Get Deep Reinforcement Learning Hands-On now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.