Container objects¶
Besides constructing neural networks through creating a subclass of Block,
Gluon provides containers to facilitate the construction.
Example
Import modules
>>> from mxnet import np, npx
>>> from mxnet.gluon import nn
>>> npx.set_np()
Construct a MLP
>>> net = nn.Sequential()
>>> net.add(nn.Dense(10, activation='relu'),
... nn.Dense(2))
Initialize the network and run forward
>>> net.initialize()
>>> x = np.random.uniform(size=(4, 20))
>>> print(net(x))
[[-0.01270512 0.01225275]
[-0.01303939 0.01191816]
[-0.01165176 0.00252366]
[-0.02191715 0.01045103]]
nn.Sequential([prefix, params]) |
Stacks Blocks sequentially. |
nn.HybridSequential([prefix, params]) |
Stacks HybridBlocks sequentially. |
contrib.nn.Concurrent([axis, prefix, params]) |
Lays Block s concurrently. |
contrib.nn.HybridConcurrent([axis, prefix, …]) |
Lays HybridBlock s concurrently. |