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 2018/05/11 18:51:55 UTC

[GitHub] szha closed pull request #10886: Added nullptr check for LeakyRelu gamma parameter.

szha closed pull request #10886: Added nullptr check for LeakyRelu gamma parameter.
URL: https://github.com/apache/incubator-mxnet/pull/10886
 
 
   

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/Jenkinsfile b/Jenkinsfile
index d1dfd30f671..90becde0b07 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -260,6 +260,9 @@ try {
             stash includes: 'build/cpp-package/example/googlenet', name: 'cpp_googlenet'
             stash includes: 'build/cpp-package/example/lenet_with_mxdataiter', name: 'cpp_lenet_with_mxdataiter'
             stash includes: 'build/cpp-package/example/resnet', name: 'cpp_resnet'
+            stash includes: 'build/cpp-package/example/mlp', name: 'cpp_mlp'
+            stash includes: 'build/cpp-package/example/mlp_cpu', name: 'cpp_mlp_cpu'
+            stash includes: 'build/cpp-package/example/mlp_gpu', name: 'cpp_mlp_gpu'
             stash includes: 'build/cpp-package/example/test_score', name: 'cpp_test_score'
             stash includes: 'build/cpp-package/example/test_optimizer', name: 'cpp_test_optimizer'
           }
@@ -791,6 +794,9 @@ try {
             unstash 'cpp_googlenet'
             unstash 'cpp_lenet_with_mxdataiter'
             unstash 'cpp_resnet'
+            unstash 'cpp_mlp'
+            unstash 'cpp_mlp_cpu'
+            unstash 'cpp_mlp_gpu'
             unstash 'cpp_test_score'
             unstash 'cpp_test_optimizer'
             sh "ci/build.py --nvidiadocker --platform ubuntu_gpu /work/runtime_functions.sh integrationtest_ubuntu_gpu_cpp_package"
diff --git a/cpp-package/example/mlp_cpu.cpp b/cpp-package/example/mlp_cpu.cpp
index ebb0eca7569..dc1ab36727d 100644
--- a/cpp-package/example/mlp_cpu.cpp
+++ b/cpp-package/example/mlp_cpu.cpp
@@ -21,6 +21,7 @@
  * Xin Li yakumolx@gmail.com
  */
 #include <chrono>
+#include "utils.h"
 #include "mxnet-cpp/MxNetCpp.h"
 
 using namespace mxnet::cpp;
@@ -55,18 +56,17 @@ int main(int argc, char** argv) {
   const float learning_rate = 0.1;
   const float weight_decay = 1e-2;
 
-  auto train_iter = MXDataIter("MNISTIter")
-      .SetParam("image", "./mnist_data/train-images-idx3-ubyte")
-      .SetParam("label", "./mnist_data/train-labels-idx1-ubyte")
-      .SetParam("batch_size", batch_size)
-      .SetParam("flat", 1)
-      .CreateDataIter();
-  auto val_iter = MXDataIter("MNISTIter")
-      .SetParam("image", "./mnist_data/t10k-images-idx3-ubyte")
-      .SetParam("label", "./mnist_data/t10k-labels-idx1-ubyte")
-      .SetParam("batch_size", batch_size)
-      .SetParam("flat", 1)
-      .CreateDataIter();
+  std::vector<std::string> data_files = { "./data/mnist_data/train-images-idx3-ubyte",
+                                          "./data/mnist_data/train-labels-idx1-ubyte",
+                                          "./data/mnist_data/t10k-images-idx3-ubyte",
+                                          "./data/mnist_data/t10k-labels-idx1-ubyte"
+                                        };
+
+  auto train_iter =  MXDataIter("MNISTIter");
+  setDataIter(&train_iter, "Train", data_files, batch_size);
+
+  auto val_iter = MXDataIter("MNISTIter");
+  setDataIter(&val_iter, "Label", data_files, batch_size);
 
   auto net = mlp(layers);
 
diff --git a/cpp-package/example/mlp_gpu.cpp b/cpp-package/example/mlp_gpu.cpp
index 8c620db23ae..67992a19f9f 100644
--- a/cpp-package/example/mlp_gpu.cpp
+++ b/cpp-package/example/mlp_gpu.cpp
@@ -21,6 +21,7 @@
  * Xin Li yakumolx@gmail.com
  */
 #include <chrono>
+#include "utils.h"
 #include "mxnet-cpp/MxNetCpp.h"
 
 using namespace mxnet::cpp;
@@ -55,18 +56,17 @@ int main(int argc, char** argv) {
   const float learning_rate = 0.1;
   const float weight_decay = 1e-2;
 
-  auto train_iter = MXDataIter("MNISTIter")
-      .SetParam("image", "./mnist_data/train-images-idx3-ubyte")
-      .SetParam("label", "./mnist_data/train-labels-idx1-ubyte")
-      .SetParam("batch_size", batch_size)
-      .SetParam("flat", 1)
-      .CreateDataIter();
-  auto val_iter = MXDataIter("MNISTIter")
-      .SetParam("image", "./mnist_data/t10k-images-idx3-ubyte")
-      .SetParam("label", "./mnist_data/t10k-labels-idx1-ubyte")
-      .SetParam("batch_size", batch_size)
-      .SetParam("flat", 1)
-      .CreateDataIter();
+  std::vector<std::string> data_files = { "./data/mnist_data/train-images-idx3-ubyte",
+                                          "./data/mnist_data/train-labels-idx1-ubyte",
+                                          "./data/mnist_data/t10k-images-idx3-ubyte",
+                                          "./data/mnist_data/t10k-labels-idx1-ubyte"
+                                        };
+
+  auto train_iter =  MXDataIter("MNISTIter");
+  setDataIter(&train_iter, "Train", data_files, batch_size);
+
+  auto val_iter = MXDataIter("MNISTIter");
+  setDataIter(&val_iter, "Label", data_files, batch_size);
 
   auto net = mlp(layers);
 
diff --git a/cpp-package/include/mxnet-cpp/operator.hpp b/cpp-package/include/mxnet-cpp/operator.hpp
index a0100cd601b..f4ce43d58d2 100644
--- a/cpp-package/include/mxnet-cpp/operator.hpp
+++ b/cpp-package/include/mxnet-cpp/operator.hpp
@@ -159,9 +159,11 @@ inline void Operator::Invoke(NDArray &output) {
 }
 
 inline Operator &Operator::SetInput(const std::string &name, Symbol symbol) {
-  input_keys_.push_back(name.c_str());
-  input_symbols_.push_back(symbol.GetHandle());
-  return *this;
+    if (symbol.GetHandle()) {
+      input_keys_.push_back(name.c_str());
+      input_symbols_.push_back(symbol.GetHandle());
+    }
+    return *this;
 }
 
 inline Operator &Operator::SetInput(const std::string &name, NDArray ndarray) {
diff --git a/cpp-package/include/mxnet-cpp/symbol.h b/cpp-package/include/mxnet-cpp/symbol.h
index 127ef156eb6..1c825c1502a 100644
--- a/cpp-package/include/mxnet-cpp/symbol.h
+++ b/cpp-package/include/mxnet-cpp/symbol.h
@@ -138,7 +138,7 @@ class Symbol {
   /*!
   * \return the SymbolHandle
   */
-  SymbolHandle GetHandle() const { return blob_ptr_->handle_; }
+  SymbolHandle GetHandle() const { return (blob_ptr_) ? blob_ptr_->handle_: NULL; }
   /*!
   * \brief construct an operator Symbol, with given input Symbol and config
   * \param name the name of the Symbol
diff --git a/cpp-package/tests/ci_test.sh b/cpp-package/tests/ci_test.sh
index 55bcad44ae6..57007f3a81d 100755
--- a/cpp-package/tests/ci_test.sh
+++ b/cpp-package/tests/ci_test.sh
@@ -36,6 +36,15 @@ cp ../../build/cpp-package/example/lenet_with_mxdataiter .
 cp ../../build/cpp-package/example/resnet .
 ./resnet 5
 
+cp ../../build/cpp-package/example/mlp .
+./mlp
+
+cp ../../build/cpp-package/example/mlp_cpu .
+./mlp_cpu
+
+cp ../../build/cpp-package/example/mlp_gpu .
+./mlp_gpu
+
  cp ../../build/cpp-package/example/test_optimizer .
  ./test_optimizer
 


 

----------------------------------------------------------------
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