From 45ef9b7567474401051ad6b72876a06c0ca6a66e Mon Sep 17 00:00:00 2001 From: Qing Date: Tue, 11 Dec 2018 16:03:24 -0800 Subject: [PATCH 1/3] add examples and fix the dependency problem --- scala-package/mxnet-demo/java-demo/bin/java_sample.sh | 2 +- scala-package/mxnet-demo/java-demo/bin/run_od.sh | 2 +- .../mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scala-package/mxnet-demo/java-demo/bin/java_sample.sh b/scala-package/mxnet-demo/java-demo/bin/java_sample.sh index 2ec9a78c3233..4fb724aca8db 100644 --- a/scala-package/mxnet-demo/java-demo/bin/java_sample.sh +++ b/scala-package/mxnet-demo/java-demo/bin/java_sample.sh @@ -16,5 +16,5 @@ # under the License. #!/bin/bash CURR_DIR=$(cd $(dirname $0)/../; pwd) -CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/classes/lib/* +CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/dependency/* java -Xmx8G -cp $CLASSPATH mxnet.HelloWorld \ No newline at end of file diff --git a/scala-package/mxnet-demo/java-demo/bin/run_od.sh b/scala-package/mxnet-demo/java-demo/bin/run_od.sh index e3c8fd545048..abd0bf5b1b93 100644 --- a/scala-package/mxnet-demo/java-demo/bin/run_od.sh +++ b/scala-package/mxnet-demo/java-demo/bin/run_od.sh @@ -16,5 +16,5 @@ # under the License. #!/bin/bash CURR_DIR=$(cd $(dirname $0)/../; pwd) -CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/classes/lib/* +CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/dependency/* java -Xmx8G -cp $CLASSPATH mxnet.ObjectDetection \ No newline at end of file diff --git a/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java b/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java index 3f209a6c6c84..71981e2691c5 100644 --- a/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java +++ b/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java @@ -20,9 +20,13 @@ import java.util.Arrays; public class HelloWorld { + static NDArray$ NDArray = NDArray$.MODULE$; + public static void main(String[] args) { System.out.println("Hello World!"); NDArray nd = new NDArray(new float[]{2.0f, 3.0f}, new Shape(new int[]{1, 2}), Context.cpu()); System.out.println(nd.shape()); + NDArray nd2 = NDArray.dot(NDArray.new dotParam(nd, nd.T()))[0]; + System.out.println(Arrays.toString(nd2.toArray())); } } From 6a5adf7f3f77ee9c5598f528b727639fb33c426c Mon Sep 17 00:00:00 2001 From: Qing Date: Wed, 12 Dec 2018 16:39:23 -0800 Subject: [PATCH 2/3] add Nightly run and optimized script --- ci/docker/runtime_functions.sh | 8 ++++++++ scala-package/mxnet-demo/java-demo/Makefile | 2 +- scala-package/mxnet-demo/java-demo/bin/java_sample.sh | 0 scala-package/mxnet-demo/java-demo/bin/run_od.sh | 0 tests/nightly/Jenkinsfile | 8 ++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) mode change 100644 => 100755 scala-package/mxnet-demo/java-demo/bin/java_sample.sh mode change 100644 => 100755 scala-package/mxnet-demo/java-demo/bin/run_od.sh diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh index f88e867b0d49..09b5ee0a30b8 100755 --- a/ci/docker/runtime_functions.sh +++ b/ci/docker/runtime_functions.sh @@ -1210,6 +1210,14 @@ nightly_tutorial_test_ubuntu_python2_gpu() { nosetests-3.4 $NOSE_TIMER_ARGUMENTS --with-xunit --xunit-file nosetests_tutorials.xml test_tutorials.py --nologcapture } +nightly_java_demo_test_cpu() { + set -ex + cd /work/mxnet/scala-package/mxnet-demo/java-demo + make javademo + ./bin/java_sample.sh + ./bin/run_od.sh +} + # Deploy diff --git a/scala-package/mxnet-demo/java-demo/Makefile b/scala-package/mxnet-demo/java-demo/Makefile index bb47db1c6d27..e4698bbcea38 100644 --- a/scala-package/mxnet-demo/java-demo/Makefile +++ b/scala-package/mxnet-demo/java-demo/Makefile @@ -16,7 +16,7 @@ # under the License. SCALA_VERSION_PROFILE := 2.11 -MXNET_VERSION := 1.4.0-SNAPSHOT +MXNET_VERSION := [1.4.0-SNAPSHOT,\) ifeq ($(OS),Windows_NT) UNAME_S := Windows diff --git a/scala-package/mxnet-demo/java-demo/bin/java_sample.sh b/scala-package/mxnet-demo/java-demo/bin/java_sample.sh old mode 100644 new mode 100755 diff --git a/scala-package/mxnet-demo/java-demo/bin/run_od.sh b/scala-package/mxnet-demo/java-demo/bin/run_od.sh old mode 100644 new mode 100755 diff --git a/tests/nightly/Jenkinsfile b/tests/nightly/Jenkinsfile index d769f08abfc5..b8e2849fd6a3 100755 --- a/tests/nightly/Jenkinsfile +++ b/tests/nightly/Jenkinsfile @@ -113,6 +113,14 @@ core_logic: { } } }, + 'Java Demo: CPU': { + node(NODE_LINUX_CPU) { + ws('workspace/java-demo') { + utils.init_git() + utils.docker_run('ubuntu_nightly_cpu', 'nightly_java_demo_test_cpu', false) + } + } + }, 'MXNetJS: CPU': { node(NODE_LINUX_CPU) { ws('workspace/nt-mxnetjs') { From 88ce723b9d378380d2a1aab8951252c4ed3a660d Mon Sep 17 00:00:00 2001 From: Qing Date: Wed, 2 Jan 2019 16:30:26 -0800 Subject: [PATCH 3/3] add explanation for the line --- scala-package/mxnet-demo/java-demo/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scala-package/mxnet-demo/java-demo/README.md b/scala-package/mxnet-demo/java-demo/README.md index dbe18052a899..54a56baf79e6 100644 --- a/scala-package/mxnet-demo/java-demo/README.md +++ b/scala-package/mxnet-demo/java-demo/README.md @@ -37,6 +37,13 @@ However, you have to define the Classpath before you run the demo code. More inf The `CLASSPATH` should point to the jar file you have downloaded. It will load the library automatically and run the example + +In order to use the `Param Object`. We requires user to place this line in the front: +``` +static NDArray$ NDArray = NDArray$.MODULE$; +``` +It would help to have the NDArray companion object static and accessable from the outside. + ### Object Detection using Inference API We also provide an example to do object detection, which downloads a ImageNet trained resnet50 model and runs inference on an image to return the classification result as ```Bash