Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Image Classification

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.


  1. Prerequisites
  2. Download artifacts
  3. Run the image inference example
  4. Pretrained models
  5. Infer APIs
  6. Next steps


  1. MXNet
  2. MXNet Scala Package
  3. IntelliJ IDE (or alternative IDE) project setup with the MXNet Scala 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:


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.sh before running this script.

There are few options which you can provide to run the example. Use the --help argument to list them.

./run_predictor_example.sh --help

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.
input-dir The directory of images to run inference on.
  • You must use model-dir.
  • You must use input-image and input-dir as this example shows single image inference as well as batch inference together.

Pretrained Models

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:

Next Steps

Check out the following related tutorials and examples for the Infer API: