In this tutorial, you learn how to use a built-in model zoo model (SSD) to achieve an object detection task.
This tutorial requires the installation of Java Kernel. To install Java Kernel, see the README.
%maven ai.djl:api:0.3.0
%maven ai.djl:repository:0.3.0
%maven ai.djl.mxnet:mxnet-engine:0.3.0
%maven ai.djl.mxnet:mxnet-model-zoo:0.3.0
%maven org.slf4j:slf4j-api:1.7.26
%maven org.slf4j:slf4j-simple:1.7.26
%maven net.java.dev.jna:jna:5.3.0
// See https://github.com/awslabs/djl/blob/v0.3.0/mxnet/mxnet-engine/README.md
// for more MXNet library selection options
%maven ai.djl.mxnet:mxnet-native-auto:1.6.0
import java.awt.image.*;
import java.nio.file.*;
import ai.djl.modality.cv.*;
import ai.djl.modality.cv.util.*;
import ai.djl.mxnet.zoo.*;
import ai.djl.repository.zoo.*;
import ai.djl.training.util.*;
var img = BufferedImageUtils.fromUrl("https://djl-ai.s3.amazonaws.com/resources/images/dog_bike_car.jpg");
img
In this example, you load a SSD (Single Shot MultiBox Detector) model from the MXNet model zoo. For more information about model zoo, see the Model Zoo Documentation
var model = MxModelZoo.SSD.loadModel(new ProgressBar());
var detections = model.newPredictor().predict(img);
detections
ImageVisualization.drawBoundingBoxes(img, detections);
img
Using the model zoo model provided, you can run inference with just the following three lines of code:
var img = BufferedImageUtils.fromUrl("https://djl-ai.s3.amazonaws.com/resources/images/dog_bike_car.jpg");
var model = MxModelZoo.SSD.loadModel();
var detections = model.newPredictor().predict(img);
You can find full SsdExample source code here.