-
First of all, thanks for the great work and great examples! I tried to re-create the object detection example in an existing project (OpenJDK 17, Windows 10) and used following setup (basically got all the latest version):
However, I do get the following exception:
which indicates, that there is somewhere a version mismatch. Yet another peculiar consequence is, that using the above version-interplay leads to having the model being loaded via My sandbox code: package org.vitrivr.cineast.core;
import ai.djl.Application;
import ai.djl.ModelException;
import ai.djl.engine.Engine;
import ai.djl.inference.Predictor;
import ai.djl.modality.cv.Image;
import ai.djl.modality.cv.ImageFactory;
import ai.djl.modality.cv.output.DetectedObjects;
import ai.djl.repository.zoo.Criteria;
import ai.djl.repository.zoo.ModelZoo;
import ai.djl.repository.zoo.ZooModel;
import ai.djl.training.util.ProgressBar;
import ai.djl.translate.TranslateException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Sandbox {
private static final Logger logger = LoggerFactory.getLogger(Sandbox.class);
public static void main(String[] args) throws IOException, ModelException, TranslateException {
DetectedObjects detection = predict();
logger.info("{}", detection);
}
public static DetectedObjects predict() throws IOException, ModelException, TranslateException {
String url = "https://github.com/awslabs/djl/raw/master/examples/src/test/resources/dog_bike_car.jpg";
Image img = ImageFactory.getInstance().fromUrl(url);
String backbone;
if ("TensorFlow".equals(Engine.getDefaultEngineName())) {
backbone = "mobilenet_v2";
} else {
backbone = "resnet50";
}
Criteria<Image, DetectedObjects> criteria =
Criteria.builder()
.optApplication(Application.CV.OBJECT_DETECTION)
.setTypes(Image.class, DetectedObjects.class)
.optFilter("backbone", backbone)
.optEngine(Engine.getDefaultEngineName())
.optProgress(new ProgressBar())
.build();
try (ZooModel<Image, DetectedObjects> model = ModelZoo.loadModel(criteria)) {
try (Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
DetectedObjects detection = predictor.predict(img);
saveBoundingBoxImage(img, detection);
return detection;
}
}
}
private static void saveBoundingBoxImage(Image img, DetectedObjects detection)
throws IOException {
Path outputDir = Paths.get("build/output");
Files.createDirectories(outputDir);
img.drawBoundingBoxes(detection);
Path imagePath = outputDir.resolve("detected-dog_bike_car.png");
// OpenJDK can't save jpg with alpha channel
img.save(Files.newOutputStream(imagePath), "png");
logger.info("Detected objects image has been saved in: {}", imagePath);
}
} Can anyone with more experience / knowledge in this domain point me to the version mismatch? Cloning the djl repository and running the example from scratch works without a problem. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We strongly recommend you to use DJL's BOM. It ensure all the versions are matching with each other. Both You can find deprecated package information here: https://docs.djl.ai/master/docs/development/dependency_management.html |
Beta Was this translation helpful? Give feedback.
We strongly recommend you to use DJL's BOM. It ensure all the versions are matching with each other.
Both
ai.djl:repository
andai.djl.pytorch:pytorch-native-auto
are deprecated. Please remove them from the dependency.You can find deprecated package information here: https://docs.djl.ai/master/docs/development/dependency_management.html