Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SSD Inference example in Joule
import ai.djl.modality.cv.DetectedObjects;
import ai.djl.modality.cv.ImageVisualization;
import ai.djl.modality.cv.util.BufferedImageUtils;
import ai.djl.mxnet.zoo.MxModelZoo;
import ai.djl.repository.zoo.ZooModel;
import ai.djl.training.util.ProgressBar;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
public class SimpleSSDExample {
public static void main(String[] args) throws Exception{
// Get image file path
BufferedImage img = BufferedImageUtils
.fromUrl("https://raw.githubusercontent.com/dmlc/web-data/master/gluoncv/pose/soccer.png");
//Get resnet model from model zoo.
ZooModel<BufferedImage, DetectedObjects> model =
MxModelZoo.SSD.loadModel(new ProgressBar());
//Create a new predictor from model and predict on image.
DetectedObjects predictResult = model.newPredictor().predict(img);
// Draw Bounding boxes on image
ImageVisualization.drawBoundingBoxes(img, predictResult);
//Save result
ImageIO.write(img, "png", new File("ssd.png"));
model.close();
}
}
@frankfliu

This comment has been minimized.

Copy link

@frankfliu frankfliu commented Nov 27, 2019

import ai.djl.modality.cv.DetectedObjects;
import ai.djl.modality.cv.ImageVisualization;
import ai.djl.modality.cv.util.BufferedImageUtils;
import ai.djl.mxnet.zoo.MxModelZoo;
import ai.djl.repository.zoo.ZooModel;
import ai.djl.training.util.ProgressBar;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

public final class SimpleSSDExample {

public static void main(String[] args) throws Exception {
    // Get image file path
    BufferedImage img = BufferedImageUtils.fromUrl("https://djl-ai.s3.amazonaws.com/resources/images/dog_bike_car.jpg"));

    //Get resnet model from model zoo.
    ZooModel<BufferedImage, DetectedObjects> model = MxModelZoo.SSD.loadModel(new ProgressBar());
    //Create a new predictor from model and predict on image.
    DetectedObjects predictResult = model.newPredictor().predict(img);
    // Draw Bounding boxes on image
    ImageVisualization.drawBoundingBoxes(img, predictResult);
    //Save result
    ImageIO.write(img, "png", new File("ssd.png"));
    model.close();
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment