This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd8e510
commit a087228
Showing
3 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
scala-package/examples/scripts/infer/predictor/run_predictor_java_example.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# 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. | ||
|
||
hw_type=cpu | ||
if [[ $3 = gpu ]] | ||
then | ||
hw_type=gpu | ||
fi | ||
|
||
platform=linux-x86_64 | ||
|
||
if [[ $OSTYPE = [darwin]* ]] | ||
then | ||
platform=osx-x86_64 | ||
fi | ||
|
||
MXNET_ROOT=$(cd "$(dirname $0)/../../../../../"; pwd) | ||
CLASS_PATH=$MXNET_ROOT/scala-package/assembly/$platform-$hw_type/target/*:$MXNET_ROOT/scala-package/examples/target/*:$MXNET_ROOT/scala-package/examples/target/classes/lib/*:$MXNET_ROOT/scala-package/infer/target/* | ||
|
||
# model dir and prefix | ||
MODEL_DIR=$1 | ||
# input image | ||
INPUT_IMG=$2 | ||
|
||
java -Xmx8G -cp $CLASS_PATH \ | ||
org.apache.mxnetexamples.javaapi.infer.predictor.PredictorExample \ | ||
--model-path-prefix $MODEL_DIR \ | ||
--input-image $INPUT_IMG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...amples/src/main/java/org/apache/mxnetexamples/javaapi/infer/predictor/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Image Classification using Java Predictor | ||
|
||
In this example, you will learn how to use Java Inference API to | ||
build and run pre-trained Resnet 18 model. | ||
|
||
## Contents | ||
|
||
1. [Prerequisites](#prerequisites) | ||
2. [Download artifacts](#download-artifacts) | ||
3. [Setup datapath and parameters](#setup-datapath-and-parameters) | ||
4. [Run the image inference example](#run-the-image-inference-example) | ||
|
||
## Prerequisites | ||
|
||
1. MXNet | ||
2. MXNet Scala Package | ||
3. [IntelliJ IDE (or alternative IDE) project setup](https://github.com/apache/incubator-mxnet/blob/master/docs/tutorials/java/mxnet_java_on_intellij.md) with the MXNet Java Package | ||
4. wget | ||
|
||
## Download Artifacts | ||
|
||
For this tutorial, you can get the model and sample input image by running following bash file. This script will use `wget` to download these artifacts from AWS S3. | ||
|
||
From the `scala-package/examples/scripts/infer/imageclassifier/` folder run: | ||
|
||
```bash | ||
./get_resnet_18_data.sh | ||
``` | ||
|
||
**Note**: You may need to run `chmod +x get_resnet_18_data.sh` before running this script. | ||
|
||
### Setup Datapath and Parameters | ||
|
||
The available arguments are as follows: | ||
|
||
| Argument | Comments | | ||
| ----------------------------- | ---------------------------------------- | | ||
| `model-dir` | Folder path with prefix to the model (including json, params, and any synset file). | | ||
| `input-image` | The image to run inference on. | | ||
|
||
## Run the image inference example | ||
|
||
After the previous steps, you should be able to run the code using the following script that will pass all of the required parameters to the Infer API. | ||
|
||
From the `scala-package/examples/scripts/infer/predictor/` folder run: | ||
|
||
```bash | ||
bash run_predictor_java_example.sh ../models/resnet-18/resnet-18 ../images/kitten.jpg | ||
``` | ||
|
||
**Notes**: | ||
* These are relative paths to this script. | ||
* You may need to run `chmod +x run_predictor_java_example.sh` before running this script. | ||
|
||
The example should give expected output as shown below: | ||
``` | ||
Probability : 0.30337515 Class : n02123159 tiger cat | ||
Probability : 0.30337515 Class : n02123159 tiger cat | ||
``` | ||
the outputs come from the the input image, with top1 predictions picked. |