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/11/27 21:33:08 UTC

[GitHub] nswamy closed pull request #13358: Java demo file-path fix

nswamy closed pull request #13358: Java demo file-path fix
URL: https://github.com/apache/incubator-mxnet/pull/13358
 
 
   

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/scala-package/mxnet-demo/java-demo/Makefile b/scala-package/mxnet-demo/java-demo/Makefile
index 340a50f7596..6b76e272f9e 100644
--- a/scala-package/mxnet-demo/java-demo/Makefile
+++ b/scala-package/mxnet-demo/java-demo/Makefile
@@ -16,7 +16,6 @@
 # under the License.
 
 SCALA_VERSION_PROFILE := 2.11
-SCALA_VERSION := 2.11.8
 MXNET_VERSION := 1.3.1-SNAPSHOT
 
 ifeq ($(OS),Windows_NT)
@@ -42,13 +41,11 @@ else
 endif
 
 javademo:
-	(mvn package -Dmxnet.profile=$(SCALA_PKG_PROFILE) \
+	(mvn install dependency:copy-dependencies package -Dmxnet.profile=$(SCALA_PKG_PROFILE) \
 		-Dmxnet.scalaprofile=$(SCALA_VERSION_PROFILE) \
-		-Dmxnet.version=$(MXNET_VERSION) \
-		-Dscala.version=$(SCALA_VERSION))
+		-Dmxnet.version=$(MXNET_VERSION))
 
 javaclean:
 	(mvn clean -Dmxnet.profile=$(SCALA_PKG_PROFILE) \
 		-Dmxnet.scalaprofile=$(SCALA_VERSION_PROFILE) \
-		-Dmxnet.version=$(MXNET_VERSION) \
-		-Dscala.version=$(SCALA_VERSION))
\ No newline at end of file
+		-Dmxnet.version=$(MXNET_VERSION))
diff --git a/scala-package/mxnet-demo/java-demo/README.md b/scala-package/mxnet-demo/java-demo/README.md
index ffe614a2928..55b4d914b83 100644
--- a/scala-package/mxnet-demo/java-demo/README.md
+++ b/scala-package/mxnet-demo/java-demo/README.md
@@ -1,38 +1,41 @@
 # MXNet Java Sample Project
 This is an project created to use Maven-published Scala/Java package with two Java examples.
 ## Setup
-Please copy the downloaded MXNet Java package jar file under the `java-demo` folder.
-
+You can use the `Makefile` to make the Java package. Simply do the following:
+```Bash
+make javademo
+```
+This will load the default parameter for all the environment variable.
+If you want to run with GPU on Linux, just simply add `USE_CUDA=1` when you run the make file
+ 
+You can use the following instruction as an alternative to achieve the same result:
 User are required to use `mvn package` to build the package,
  which are shown below:
 ```Bash
-export SCALA_VERSION_PROFILE=2.11 SCALA_VERSION=2.11.8 MXNET_VERSION=1.3.1-SNAPSHOT
+export SCALA_VERSION_PROFILE=2.11 MXNET_VERSION=1.3.1-SNAPSHOT
 export SCALA_PKG_PROFILE=
-mvn package -Dmxnet.profile=$(SCALA_PKG_PROFILE) \
-		-Dmxnet.scalaprofile=$(SCALA_VERSION_PROFILE) \
-		-Dmxnet.version=$(MXNET_VERSION) \
-		-Dscala.version=$(SCALA_VERSION)
+mvn package -Dmxnet.profile=$SCALA_PKG_PROFILE \
+		-Dmxnet.scalaprofile=$SCALA_VERSION_PROFILE \
+		-Dmxnet.version=$MXNET_VERSION
 ```
-These environment variable (`SCALA_PKG_PROFILE`, `SCALA_VERSION_PROFILE`, `MXNET_VERSION`, `SCALA_VERSION`)
+These environment variable (`SCALA_PKG_PROFILE`, `SCALA_VERSION_PROFILE`, `MXNET_VERSION`)
 should be set before executing the line above.
- 
-You can also use the `Makefile` as an alternative to do the same thing. Simply do the following:
-```Bash
-make javademo
-```
-This will load the default parameter for all the environment variable.
- If you want to run with GPU on Linux, just simply add `USE_CUDA=1` when you run the make file
+The `SCALA_PKG_PROFILE` should be chosen from `osx-x86_64-cpu`, `linux-x86_64-cpu` or `linux-x86_64-gpu`.
+
 
 ## Run
 ### Hello World
 The Scala file is being executed using Java. You can execute the helloWorld example as follows:
 ```Bash
-java -cp $CLASSPATH sample.HelloWorld
+bash bin/java_sample.sh
 ```
-However, you have to define the Classpath before you run the demo code. More information can be found in the `demo.sh` And you can run the bash script as follows:
+You can also run the following command manually:
 ```Bash
-bash bin/java_sample.sh
+java -cp $CLASSPATH sample.HelloWorld
 ```
+However, you have to define the Classpath before you run the demo code. More information can be found in the `java_sample.sh`.
+The `CLASSPATH` should point to the jar file you have downloaded.
+
 It will load the library automatically and run the example
 ### 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
@@ -50,11 +53,11 @@ Coord:83.82356, 179.14001, 206.63783, 476.78754
 
 you can run using the command shown below:
 ```Bash
-java -cp $CLASSPATH sample.ObjectDetection
+bash bin/run_od.sh
 ```
-or script as follows:
+or the command below as an alternative
 ```Bash
-bash bin/run_od.sh
+java -cp $CLASSPATH sample.ObjectDetection
 ```
 
 If you want to test run on GPU, you can set a environment variable as follows:
@@ -73,4 +76,9 @@ If you are facing opencv issue on Ubuntu, please try as follows to install openc
 sudo add-apt-repository ppa:timsc/opencv-3.4
 sudo apt-get update
 sudo apt install libopencv-imgcodecs3.4
-```
\ No newline at end of file
+```
+
+Is there any other version available?
+
+You can find nightly release version from [here](https://repository.apache.org/#nexus-search;gav~org.apache.mxnet~~1.3.1-SNAPSHOT~~).
+Please keep the same version in the Makefile or [above version](https://repository.apache.org/#nexus-search;gav~org.apache.mxnet~~~~) to run this demo.
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 50e7fb9eb97..2ec9a78c323 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/*
-java -Xmx8G  -cp $CLASSPATH sample.HelloWorld
\ No newline at end of file
+CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/classes/lib/*
+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 5cbc53fbcef..e3c8fd54504 100644
--- a/scala-package/mxnet-demo/java-demo/bin/run_od.sh
+++ b/scala-package/mxnet-demo/java-demo/bin/run_od.sh
@@ -16,6 +16,5 @@
 # under the License.
 #!/bin/bash
 CURR_DIR=$(cd $(dirname $0)/../; pwd)
-
-CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/*
-java -Xmx8G  -cp $CLASSPATH sample.ObjectDetection
\ No newline at end of file
+CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/classes/lib/*
+java -Xmx8G  -cp $CLASSPATH mxnet.ObjectDetection
\ No newline at end of file
diff --git a/scala-package/mxnet-demo/java-demo/pom.xml b/scala-package/mxnet-demo/java-demo/pom.xml
index 5014d2e09f5..cfbe8d82a6b 100644
--- a/scala-package/mxnet-demo/java-demo/pom.xml
+++ b/scala-package/mxnet-demo/java-demo/pom.xml
@@ -8,13 +8,23 @@
     <version>1.0-SNAPSHOT</version>
     <name>MXNet Java Demo</name>
 
+    <repositories>
+        <repository>
+            <id>Apache Snapshot</id>
+            <url>https://repository.apache.org/content/groups/snapshots</url>
+        </repository>
+    </repositories>
+
+    <properties>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.mxnet</groupId>
             <artifactId>mxnet-full_${mxnet.scalaprofile}-${mxnet.profile}</artifactId>
             <version>${mxnet.version}</version>
-            <scope>system</scope>
-            <systemPath>${project.basedir}/mxnet-full_${mxnet.scalaprofile}-${mxnet.profile}-${mxnet.version}.jar</systemPath>
         </dependency>
         <dependency>
             <groupId>commons-io</groupId>
@@ -22,4 +32,5 @@
             <version>2.4</version>
         </dependency>
     </dependencies>
+
 </project>
\ No newline at end of file
diff --git a/scala-package/mxnet-demo/java-demo/src/main/java/sample/HelloWorld.java b/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java
similarity index 98%
rename from scala-package/mxnet-demo/java-demo/src/main/java/sample/HelloWorld.java
rename to scala-package/mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java
index 60619dc8a80..3f209a6c6c8 100644
--- a/scala-package/mxnet-demo/java-demo/src/main/java/sample/HelloWorld.java
+++ b/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/HelloWorld.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package sample;
+package mxnet;
 
 import org.apache.mxnet.javaapi.*;
 import java.util.Arrays;
diff --git a/scala-package/mxnet-demo/java-demo/src/main/java/sample/ObjectDetection.java b/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/ObjectDetection.java
similarity index 98%
rename from scala-package/mxnet-demo/java-demo/src/main/java/sample/ObjectDetection.java
rename to scala-package/mxnet-demo/java-demo/src/main/java/mxnet/ObjectDetection.java
index bf9a93ae821..cfe9b66c4b3 100644
--- a/scala-package/mxnet-demo/java-demo/src/main/java/sample/ObjectDetection.java
+++ b/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/ObjectDetection.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package sample;
+package mxnet;
 import org.apache.mxnet.infer.javaapi.ObjectDetectorOutput;
 import org.apache.mxnet.javaapi.*;
 import org.apache.mxnet.infer.javaapi.ObjectDetector;
@@ -46,7 +46,7 @@ public static void downloadModelImage() {
         imagePath = tempDirPath + "/inputImages/resnetssd/dog-ssd.jpg";
         String imgURL = "https://s3.amazonaws.com/model-server/inputs/dog-ssd.jpg";
         downloadUrl(imgURL, imagePath);
-        modelPath = tempDirPath + "resnetssd/resnet50_ssd_model";
+        modelPath = tempDirPath + "/resnetssd/resnet50_ssd_model";
         System.out.println("Download model files, this can take a while...");
         String modelURL = "https://s3.amazonaws.com/model-server/models/resnet50_ssd/";
         downloadUrl(modelURL + "resnet50_ssd_model-symbol.json",


 

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