码迷,mamicode.com
首页 > Web开发 > 详细

mxnet-Sequential

时间:2018-11-13 20:16:28      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:use   ann   print   stride   follow   ceil   none   initial   des   

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Fri Aug 10 16:13:29 2018 @author: myhaspl """ from mxnet import nd from mxnet.gluon import nn net = nn.Sequential() # Add a sequence of layers. net.add( # Similar to Dense, it is not necessary to specify the # input channels by the argument `in_channels`, which will be # automatically inferred in the first forward pass. Also, # we apply a relu activation on the output. # # In addition, we can use a tuple to specify a # non-square kernel size, such as `kernel_size=(2,4) nn.Conv2D(channels=6, kernel_size=5, activation=‘relu‘), # One can also use a tuple to specify non-symmetric # pool and stride sizes nn.MaxPool2D(pool_size=2, strides=2), nn.Conv2D(channels=16, kernel_size=3, activation=‘relu‘), nn.MaxPool2D(pool_size=2, strides=2), # flatten the 4-D input into 2-D with shape # `(x.shape[0], x.size/x.shape[0])` so that it can be used # by the following dense layers nn.Flatten(), nn.Dense(120, activation="relu"), nn.Dense(84, activation="relu"), nn.Dense(10)) print net net.initialize() x = nd.random.uniform(shape=(4,1,28,28)) y = net(x) print y.shape print net[0].weight.data().shape print net[7].weight.data().shape Sequential( ? (0): Conv2D(None -> 6, kernel_size=(5, 5), stride=(1, 1)) ? (1): MaxPool2D(size=(2, 2), stride=(2, 2), padding=(0, 0), ceil_mode=False) ? (2): Conv2D(None -> 16, kernel_size=(3, 3), stride=(1, 1)) ? (3): MaxPool2D(size=(2, 2), stride=(2, 2), padding=(0, 0), ceil_mode=False) ? (4): Flatten ? (5): Dense(None -> 120, Activation(relu)) ? (6): Dense(None -> 84, Activation(relu)) ? (7): Dense(None -> 10, linear) )

(4L, 10L)
(6L, 1L, 5L, 5L)
(10L, 84L)

mxnet-Sequential

标签:use   ann   print   stride   follow   ceil   none   initial   des   

原文地址:http://blog.51cto.com/13959448/2316507

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!