This folder contains an example for image classification with the MXNet Scala Infer API. The goal of image classification is to identify the objects contained in images. The following example shows recognized object classes with corresponding probabilities using a pre-trained model.
- Download artifacts
- Run the image inference example
- Pretrained models
- Infer APIs
- Next steps
- MXNet Scala Package
- IntelliJ IDE (or alternative IDE) project setup with the MXNet Scala Package
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.
scala-package/examples/scripts/infer/imageclassifier/ folder run:
Note: You may need to run
chmod +x get_resnet_data.sh before running this script.
Run the Image Inference Example
Now that you have the model files and the test kitten image, you can run the following script to pass the necessary parameters to the JDK to run this inference example.
./run_classifier_example.sh \ ../resnet/resnet-152 ../images/kitten.jpg ../images/
- These are relative paths to this script.
- You may need to run
chmod +x run_predictor_example.shbefore running this script.
There are few options which you can provide to run the example. Use the
--help argument to list them.
The available arguments are as follows:
||Folder path with prefix to the model (including json, params, and any synset file).|
||The image to run inference on.|
||The directory of images to run inference on.|
- You must use
- You must use
input-diras this example shows single image inference as well as batch inference together.
The MXNet project repository provides several pre-trained models on various datasets and examples on how to train them. You may use the modelzoo.py helper script to download these models. Many ImageNet models may be also be downloaded directly from http://data.mxnet.io/models/imagenet/.
Infer API Details
This example uses the ImageClassifier
class provided by the MXNet Scala Infer API.
It provides methods to load the images, create a NDArray out of a
BufferedImage, and run prediction using the following Infer APIs:
Check out the following related tutorials and examples for the Infer API: