Image Classification API


Analytics Zoo provides a collection of pre-trained models for Image Classification. These models can be used for out-of-the-box inference if you are interested in categories already in the corresponding datasets. According to the business scenarios, users can embed the models locally, distributedly in Spark such as Apache Storm and Apache Flink.

Image Classification examples

Analytics Zoo provides several typical kind of pre-trained Image Classfication models : Alexnet, Inception-V1, VGG, Resnet, Densenet, Mobilenet, Squeezenet models. To use these models, please check below examples.

Scala

Scala example

It's very easy to apply the model for inference with below code piece.

val imc = ImageClassifier.loadModel[Float](params.model)
val data = ImageSet.read(params.image, sc, params.nPartition)
val output = imc.predictImageSet(data)

User can also define his own configuration to do the inference with below code piece.

val imc = ImageClassifier.loadModel[Float](params.model)
val data = ImageSet.read(params.image, sc, params.nPartition)
val preprocessing = ImageResize(256, 256)-> ImageCenterCrop(224, 224) ->
        ImageChannelNormalize(123, 117, 104) ->
        ImageMatToTensor[Float]() ->
        ImageSetToSample[Float]()
val config = ImageConfigure[Float](preprocessing)        
val output = imc.predictImageSet(data, config)

Python

Python example

It's very easy to apply the model for inference with below code piece.

imc = ImageClassifier.load_model(model_path)
image_set = ImageSet.read(img_path, sc)
output = imc.predict_image_set(image_set)

User can also define his own configuration to do the inference with below code piece.

imc = ImageClassifier.load_model(model_path)
image_set = ImageSet.read(img_path, sc)
preprocessing = ChainedPreprocessing(
                [ImageResize(256, 256), ImageCenterCrop(224, 224),
                ImageChannelNormalize(123.0, 117.0, 104.0), ImageMatToTensor(),
                ImageSetToSample()])
config = ImageConfigure(preprocessing) 
output = imc.predict_image_set(image_set)

For preprocessors for Image Classification models, please check Image Classification Config