You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/12 22:07:12 UTC

[GitHub] piiswrong closed pull request #8254: Fix softmax_cross_entropy

piiswrong closed pull request #8254: Fix softmax_cross_entropy
URL: https://github.com/apache/incubator-mxnet/pull/8254
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/operator/loss_binary_op.cc b/src/operator/loss_binary_op.cc
index d0a77946ff..3e7d15c317 100644
--- a/src/operator/loss_binary_op.cc
+++ b/src/operator/loss_binary_op.cc
@@ -58,6 +58,10 @@ Example::
 )code" ADD_FILELINE)
 .set_num_inputs(2)
 .set_num_outputs(1)
+.set_attr<nnvm::FListInputNames>("FListInputNames",
+  [](const NodeAttrs& attrs) {
+    return std::vector<std::string>{"data", "label"};
+  })
 .set_attr<nnvm::FInferShape>("FInferShape", SoftmaxCrossEntropyShape)
 .set_attr<nnvm::FInferType>("FInferType", ElemwiseType<2, 1>)
 .set_attr<FResourceRequest>("FResourceRequest",
diff --git a/tests/python/unittest/test_operator.py b/tests/python/unittest/test_operator.py
index b4e49a98b4..59f2d1ea40 100644
--- a/tests/python/unittest/test_operator.py
+++ b/tests/python/unittest/test_operator.py
@@ -292,6 +292,29 @@ def test_softmax():
     check_softmax_with_shape((3, 4, 2), default_context(), preserve_shape=True)
 
 
+def test_softmax_cross_entropy():
+    batch_size = 32
+    num_class = 20
+
+    data = mx.sym.Variable("data")
+    label = mx.sym.Variable("softmax_label")
+    conv = mx.sym.Convolution(data=data, kernel=(2, 2), num_filter=5)
+    flatten = mx.sym.Flatten(data=conv)
+    fc = mx.sym.FullyConnected(data=flatten, num_hidden=num_class)
+    out = mx.sym.softmax_cross_entropy(data=fc, label=label)
+
+    data_shape = (batch_size , 3, 64, 64)
+    label_shape = (batch_size,)
+    mod = mx.mod.Module(symbol=out)
+    mod.bind(data_shapes=[('data', data_shape)],
+             label_shapes=[('softmax_label', label_shape)])
+    mod.init_params()
+    mod.init_optimizer(optimizer_params={'learning_rate': 0.01})
+    mod.forward(mx.io.DataBatch(data=[mx.ndarray.normal(0, 10, shape=data_shape)],
+                                label=[mx.ndarray.arange(0, batch_size)]))
+    assert mod.get_outputs()[0].shape == (1,)
+
+
 def test_python_op():
     X = mx.symbol.Variable('X')
     op = mx.operator.NumpyOp()


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services