You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by ta...@apache.org on 2019/08/14 01:28:56 UTC
[incubator-mxnet] branch v1.5.x updated: fix LinearRegressionOutput
with empty label (#15620) (#15873)
This is an automated email from the ASF dual-hosted git repository.
taolv pushed a commit to branch v1.5.x
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/v1.5.x by this push:
new 782f1a8 fix LinearRegressionOutput with empty label (#15620) (#15873)
782f1a8 is described below
commit 782f1a8f32bda5615d5423c077fee89bc83a7a1b
Author: Tao Lv <ta...@intel.com>
AuthorDate: Wed Aug 14 09:28:08 2019 +0800
fix LinearRegressionOutput with empty label (#15620) (#15873)
---
cpp-package/example/CMakeLists.txt | 4 +++
cpp-package/example/test_regress_label.cpp | 56 ++++++++++++++++++++++++++++++
cpp-package/tests/ci_test.sh | 3 ++
src/operator/regression_output-inl.h | 3 +-
4 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/cpp-package/example/CMakeLists.txt b/cpp-package/example/CMakeLists.txt
index b4cea68..643a92d 100644
--- a/cpp-package/example/CMakeLists.txt
+++ b/cpp-package/example/CMakeLists.txt
@@ -27,6 +27,10 @@ endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
+add_executable(test_regress_label test_regress_label.cpp ${CPP_PACKAGE_HAEDERS})
+target_link_libraries(test_regress_label ${CPP_EXAMPLE_LIBS})
+add_dependencies(test_regress_label ${CPPEX_DEPS})
+
add_executable(lenet lenet.cpp ${CPP_PACKAGE_HEADERS})
target_link_libraries(lenet ${CPP_EXAMPLE_LIBS})
add_dependencies(lenet ${CPPEX_DEPS})
diff --git a/cpp-package/example/test_regress_label.cpp b/cpp-package/example/test_regress_label.cpp
new file mode 100644
index 0000000..8d1d644
--- /dev/null
+++ b/cpp-package/example/test_regress_label.cpp
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * This file is used for testing LinearRegressionOutput can
+ * still bind if label is not provided
+ */
+
+#include <iostream>
+#include <vector>
+#include <string>
+#include "dmlc/logging.h"
+#include "mxnet-cpp/MxNetCpp.h"
+
+using namespace mxnet::cpp;
+
+int main() {
+ LOG(INFO) << "Running LinearRegressionOutput symbol testing, "
+ "executor should be able to bind without label.";
+ Symbol data = Symbol::Variable("data");
+ Symbol label = Symbol::Variable("regress_label");
+ Symbol symbol = LinearRegressionOutput(data, label);
+ std::map<std::string, mxnet::cpp::OpReqType> opReqMap;
+ for (const auto& iter : symbol.ListArguments()) {
+ opReqMap[iter] = mxnet::cpp::OpReqType::kNullOp;
+ }
+ std::map<std::string, mxnet::cpp::NDArray> argMap({
+ {"data", NDArray(Shape{1, 3}, Context::cpu(), true)}
+ });
+
+ try {
+ symbol.SimpleBind(Context::cpu(),
+ argMap,
+ std::map<std::string, mxnet::cpp::NDArray>(),
+ opReqMap,
+ std::map<std::string, mxnet::cpp::NDArray>());
+ } catch (const std::exception& e) {
+ LOG(ERROR) << "Error binding the symbol: " << MXGetLastError() << " " << e.what();
+ throw;
+ }
+ return 0;
+}
diff --git a/cpp-package/tests/ci_test.sh b/cpp-package/tests/ci_test.sh
index ef7fcea..7e4cf7d 100755
--- a/cpp-package/tests/ci_test.sh
+++ b/cpp-package/tests/ci_test.sh
@@ -60,6 +60,9 @@ cp ../../build/cpp-package/example/test_score .
cp ../../build/cpp-package/example/test_ndarray_copy .
./test_ndarray_copy
+cp ../../build/cpp-package/example/test_regress_label .
+./test_regress_label
+
sh unittests/unit_test_mlp_csv.sh
cd inference
diff --git a/src/operator/regression_output-inl.h b/src/operator/regression_output-inl.h
index ba59937..dcee802 100644
--- a/src/operator/regression_output-inl.h
+++ b/src/operator/regression_output-inl.h
@@ -59,7 +59,8 @@ inline bool RegressionOpShape(const nnvm::NodeAttrs& attrs,
const mxnet::TShape &dshape = in_attrs->at(0);
if (!shape_is_known(dshape)) return false;
auto &lshape = (*in_attrs)[1];
- if (lshape.ndim() == 0) {
+ // if label is not defined, manually build the shape based on dshape
+ if (lshape.ndim() == -1) {
// special treatment for 1D output, to allow 1D label by default.
// Think about change convention later
if (dshape.ndim() == 2 && dshape[1] == 1) {