我想使用djl 加载我的模型,但是在自动下载动态库时出现了一些问题请问我该怎么解决?
这是我导入的一些依赖
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-model-zoo</artifactId>
<version>0.25.0</version>
</dependency>
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-engine</artifactId>
<version>0.25.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-auto</artifactId>
<version>1.8.1</version>
</dependency>
下面的是我加载的代码
public class Yolov5 {
static Translator<Image, DetectedObjects> translator = YoloV5Translator.builder().optSynsetArtifactName("coco.names").build();
static Criteria<Image, DetectedObjects> criteria =
Criteria.builder()
.setTypes(Image.class, DetectedObjects.class)
.optDevice(Device.cpu())
.optModelUrls(Main.class.getResource("/yolov5s").getPath())
.optModelName("best2.pt")
.optTranslator(translator)
.optEngine("PyTorch")
.build();
public static void detect(Mat mat) throws ModelNotFoundException, MalformedModelException, IOException {
ZooModel<Image, DetectedObjects> model = ModelZoo.loadModel(criteria);
Image img = MyUtils.mat2Image(mat);
long startTime = System.currentTimeMillis();
Rect rect = new Rect();
Scalar color = new Scalar(0,255, 0);
try (Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
DetectedObjects results = predictor.predict(img);
// System.out.println(results);
for (DetectedObjects.DetectedObject obj : results.<DetectedObjects.DetectedObject>items()) {
BoundingBox bbox = obj.getBoundingBox();
Rectangle rectangle = bbox.getBounds();
String showText = String.format("%s: %.2f", obj.getClassName(), obj.getProbability());
rect.x = (int) rectangle.getX();
rect.y = (int) rectangle.getY();
rect.width = (int) rectangle.getWidth();
rect.height = (int) rectangle.getHeight();
// 画框
Imgproc.rectangle(mat, rect, color, 2);
//画名字
Imgproc.putText(mat, showText,
new Point(rect.x, rect.y),
Imgproc.FONT_HERSHEY_COMPLEX,
rectangle.getWidth() / 200,
color);
}
} catch (TranslateException e) {
e.printStackTrace();
}
}
}
package com.lgw.until;
import ai.djl.modality.cv.Image;
import ai.djl.modality.cv.ImageFactory;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
public class MyUtils {
public static Image mat2Image(Mat mat) {
return ImageFactory.getInstance().fromImage(HighGui.toBufferedImage(mat));
}
}
运行时自动下载pytroch的动态库出现了一些问题
java.io.FileNotFoundException: https://publish.djl.ai/pytorch/1.8.1/jnilib/0.25.0/win-x86_64/cu111/djl_torch.dll
我打开这个连接出现了
```xml
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>publish/pytorch/1.8.1/jnilib/0.21.0/win-x86_64/cu111/djl_torch.dll</Key>
<RequestId>YM27SCMB5C8AYR4M</RequestId>
<HostId>CESZYMpghat/pM8VZXOvXuUs1i0dY0DiyZ0H83szxjaW+9NtduR50lx2UE1fdUigrPQZoGND3RE=</HostId>
</Error>
我应该怎么解决?