我们先用MXNet胶子创建一个非常基本的深层神经网络(灵感来自this tutorial):
import mxnet as mx
from mxnet import gluon
ctx = mx.cpu()
net = gluon.nn.Sequential()
with net.name_scope():
net.add(gluon.nn.Conv2D(channels=20, kernel_size=5, activation='relu'))
net.add(gluon.nn.MaxPool2D(pool_size=2, strides=2))
现在,如果我们想打印出图层的尺寸,我们所要做的就是。。。你知道吗
print(net[0])
# prints: Conv2D(None -> 20, kernel_size=(5, 5), stride=(1, 1), Activation(relu))
print(net[1])
# prints: MaxPool2D(size=(2, 2), stride=(2, 2), padding=(0, 0), ceil_mode=False)
但是,如果我们不想打印出来,而是想以编程的方式检查padding
的net[1]
呢?你知道吗
net[1].padding
时,得到错误AttributeError: 'MaxPool2D' object has no attribute 'padding'
。你知道吗net[1]['padding']
时,得到了错误TypeError: 'MaxPool2D' object is not subscriptable
。你知道吗那么,在MXNet胶子中编程访问神经网络层维度的正确方法是什么?你知道吗
print(net[1]._kwargs["pad"])
试着从夸尔格字典里找出来。在this source中查找其他键。你知道吗
This是代码的Colab链接。你知道吗
其他键是
kernel
表示内核大小,stride
表示跨距。你知道吗要获取所有键和值:
相关问题 更多 >
编程相关推荐