djl
djl copied to clipboard
I was using djl version 0.25, if I upgrade to version 0.32, do I need to change the method?
this is my POM
<!-- DJL API -->
<dependency>
<groupId>ai.djl</groupId>
<artifactId>api</artifactId>
<version>${djl.version}</version>
</dependency>
<!-- DJL PyTorch Engine -->
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-engine</artifactId>
<version>${djl.version}</version>
</dependency>
<!-- PyTorch Native Library -->
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-cpu</artifactId>
<classifier>win-x86_64</classifier>
<version>2.0.1</version>
<scope>runtime</scope>
</dependency>
<!-- DJL PyTorch Model Zoo -->
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-model-zoo</artifactId>
<version>${djl.version}</version>
</dependency>
This is my code
public void init() {
try {
String modelPath = Paths.get(modelBasePath, "fire.torchscript.pt").toString();
String synsetPath = Paths.get(modelBasePath, "fire.txt").toString();
logger.info("正在加载模型,路径: {}", modelPath);
File modelFile = new File(modelPath);
if (!modelFile.exists()) {
throw new RuntimeException("模型文件不存在: " + modelPath);
}
Translator<Image, DetectedObjects> translator = YoloV5Translator.builder()
.addTransform(new Resize(640, 480))
.addTransform(new ToTensor())
.optSynsetArtifactName(synsetPath)
.build();
Criteria<Image, DetectedObjects> criteria = Criteria.builder()
.setTypes(Image.class, DetectedObjects.class)
.optModelPath(Paths.get(modelPath))
.optTranslator(translator)
.build();
model = ModelZoo.loadModel(criteria);
logger.info("模型加载成功");
} catch (Exception e) {
logger.error("无法初始化对象检测服务: {}", e.getMessage(), e);
throw new RuntimeException("Failed to initialize object detection service", e);
}
}
public DetectedObjects detectObjects(Image image) throws Exception {
try (Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
return predictor.predict(image);
}
}
I'm using windows, my cuda version is 12.4, and I see that the documentation supports gpu acceleration, what should I do? It's not clear enough for me to view the document
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-cu124</artifactId>
<classifier>win-x86_64</classifier>
<version>2.4.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-jni</artifactId>
<version>2.4.0-0.30.0</version>
<scope>runtime</scope>
</dependency>