thomelane commented on a change in pull request #10607: New tutorial on how to create a new custom layer in Gluon URL: https://github.com/apache/incubator-mxnet/pull/10607#discussion_r182606410
########## File path: docs/tutorials/python/custom_layer.md ########## @@ -0,0 +1,247 @@ + +# How to write a custom layer in Apache MxNet Gluon API + +While Gluon API for Apache MxNet comes with [a decent number of predefined layers](https://mxnet.incubator.apache.org/api/python/gluon/nn.html), at some point one may find that a new layer is needed. Adding a new layer in Gluon API is straightforward, yet there are a few things that one needs to keep in mind. + +In this article, I will cover how to create a new layer from scratch, how to use it, what are possible pitfalls and how to avoid them. + +## The simplest custom layer + +To create a new layer in Gluon API, one must create a class that inherits from [Block](https://mxnet.incubator.apache.org/api/python/gluon/gluon.html#mxnet.gluon.Block) class. This class provides the most basic functionality, and all predefined layers inherit from it directly or via other subclasses. Because each layer in Apache MxNet inherits from `Block`, words "layer" and "block" are used interchangeably inside of the Apache MxNet community. + +The only instance method needed to be implemented is [forward()](https://mxnet.incubator.apache.org/api/python/gluon/gluon.html#mxnet.gluon.Block.forward), which defines what exactly your layer is going to do during forward propagation. Notice, that it doesn't require to provide what the block should do during backpropagation. Backpropagation pass for blocks is done by Apache MxNet for you. Review comment: Notice, that it's not required to provide what the block should do during backpropagation. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services