You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2017/08/24 17:43:55 UTC
[incubator-mxnet] branch master updated: add ctx to begin_state in
rnn_layer (#7580)
This is an automated email from the ASF dual-hosted git repository.
jxie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new b0b4664 add ctx to begin_state in rnn_layer (#7580)
b0b4664 is described below
commit b0b46641a3d3b58f7b38d8bf84b9bf0c392f3873
Author: Sheng Zha <sz...@users.noreply.github.com>
AuthorDate: Thu Aug 24 10:43:52 2017 -0700
add ctx to begin_state in rnn_layer (#7580)
* add ctx to begin_state
* fix image classification
---
example/gluon/image_classification.py | 8 ++++++--
python/mxnet/gluon/rnn/rnn_layer.py | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/example/gluon/image_classification.py b/example/gluon/image_classification.py
index 3f84ff8..b8d018d 100644
--- a/example/gluon/image_classification.py
+++ b/example/gluon/image_classification.py
@@ -57,6 +57,8 @@ parser.add_argument('--batch-norm', action='store_true',
help='enable batch normalization or not in vgg. default is false.')
parser.add_argument('--use-pretrained', action='store_true',
help='enable using pretrained model from gluon.')
+parser.add_argument('--kvstore', type=str, default='device',
+ help='kvstore to use for trainer/module.')
parser.add_argument('--log-interval', type=int, default=50, help='Number of batches to wait before logging.')
opt = parser.parse_args()
@@ -116,7 +118,8 @@ def train(epochs, ctx):
if isinstance(ctx, mx.Context):
ctx = [ctx]
net.initialize(mx.init.Xavier(magnitude=2.24), ctx=ctx)
- trainer = gluon.Trainer(net.collect_params(), 'sgd', {'learning_rate': opt.lr, 'wd': opt.wd})
+ trainer = gluon.Trainer(net.collect_params(), 'sgd', {'learning_rate': opt.lr, 'wd': opt.wd},
+ kvstore = opt.kvstore)
metric = mx.metric.Accuracy()
loss = gluon.loss.SoftmaxCrossEntropyLoss()
@@ -162,7 +165,8 @@ if __name__ == '__main__':
out = net(data)
softmax = mx.sym.SoftmaxOutput(out, name='softmax')
mod = mx.mod.Module(softmax, context=[mx.gpu(i) for i in range(gpus)] if gpus > 0 else [mx.cpu()])
- mod.fit(train_data, num_epoch=opt.epochs, batch_end_callback = mx.callback.Speedometer(batch_size, 1))
+ mod.fit(train_data, num_epoch=opt.epochs, kvstore=opt.kvstore,
+ batch_end_callback = mx.callback.Speedometer(batch_size, 1))
else:
if opt.mode == 'hybrid':
net.hybridize()
diff --git a/python/mxnet/gluon/rnn/rnn_layer.py b/python/mxnet/gluon/rnn/rnn_layer.py
index 86b7c61..063d566 100644
--- a/python/mxnet/gluon/rnn/rnn_layer.py
+++ b/python/mxnet/gluon/rnn/rnn_layer.py
@@ -141,7 +141,7 @@ class _RNNLayer(Block):
batch_size: int
Only required for `NDArray` API. Size of the batch ('N' in layout).
Dimension of the input.
- func : callable, default `symbol.zeros`
+ func : callable, default `ndarray.zeros`
Function for creating initial state.
For Symbol API, func can be `symbol.zeros`, `symbol.uniform`,
@@ -172,7 +172,7 @@ class _RNNLayer(Block):
batch_size = inputs.shape[self._layout.find('N')]
skip_states = states is None
if skip_states:
- states = self.begin_state(batch_size)
+ states = self.begin_state(batch_size, ctx=inputs.context)
if isinstance(states, ndarray.NDArray):
states = [states]
for state, info in zip(states, self.state_info(batch_size)):
--
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].