Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Java demo file-path fix (#13358)
Browse files Browse the repository at this point in the history
* fix on ubuntu

* add readme instruction

* fix intellij Tutorials

* fix intelliJ tutorial

* fix the document

* update demo

* revert the change on intelliJ tutorial

* fix make process

* fix documentation
  • Loading branch information
lanking520 authored and nswamy committed Nov 27, 2018
1 parent 8a94dbd commit 7542b2b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
9 changes: 3 additions & 6 deletions scala-package/mxnet-demo/java-demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
-Dmxnet.version=$(MXNET_VERSION))
52 changes: 30 additions & 22 deletions scala-package/mxnet-demo/java-demo/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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
```
```

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.
4 changes: 2 additions & 2 deletions scala-package/mxnet-demo/java-demo/bin/java_sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/classes/lib/*
java -Xmx8G -cp $CLASSPATH mxnet.HelloWorld
5 changes: 2 additions & 3 deletions scala-package/mxnet-demo/java-demo/bin/run_od.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
CLASSPATH=$CLASSPATH:$CURR_DIR/target/*:$CLASSPATH:$CURR_DIR/target/classes/lib/*
java -Xmx8G -cp $CLASSPATH mxnet.ObjectDetection
15 changes: 13 additions & 2 deletions scala-package/mxnet-demo/java-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@
<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>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 7542b2b

Please sign in to comment.