mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-10 03:28:49 +00:00
1、【核心升级】升级DJL版本到0.34.0
2、【平台支持】新增对 Linux ARM64 架构的全面支持 3、【通用视觉】集成零样本目标检测模型 4、【活体检测】优化视频检测流程,实现 Predictor 视频会话级复用 5、【人脸识别】SQLite人脸查询改进线程池 6、【人脸识别】修复 Milvus 向量库下 listFaces 接口的调用异常
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<smartjavaai.version>1.0.27</smartjavaai.version>
|
||||
<smartjavaai.version>1.1.0</smartjavaai.version>
|
||||
<!--如果打包运行,需要替换成你的main-->
|
||||
<exec.mainClass>smartai.examples.vision.ObjectDetectionDemo</exec.mainClass>
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-jni</artifactId>
|
||||
<version>2.5.1-0.32.0</version>
|
||||
<version>2.7.1-0.34.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.windows-x86_64}</classifier>
|
||||
<version>2.5.1</version>
|
||||
<version>2.7.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -179,12 +179,11 @@
|
||||
<classifier>${javacv.platform.linux-x86_64}</classifier>
|
||||
</dependency>
|
||||
|
||||
<!--PyTorch离线平台依赖-->
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.linux-x86_64}</classifier>
|
||||
<version>2.5.1</version>
|
||||
<version>2.7.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -203,14 +202,57 @@
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- linux aarch64 平台 (保留对应平台的配置,可以减小包大小)-->
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>javacpp</artifactId>
|
||||
<version>${javacv.version}</version>
|
||||
<classifier>${javacv.platform.linux-arm64}</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>ffmpeg</artifactId>
|
||||
<version>6.1.1-1.5.10</version>
|
||||
<classifier>${javacv.platform.linux-arm64}</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>openblas</artifactId>
|
||||
<version>0.3.26-1.5.10</version>
|
||||
<classifier>${javacv.platform.linux-arm64}</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
<version>4.9.0-1.5.10</version>
|
||||
<classifier>${javacv.platform.linux-arm64}</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-cpu-precxx11</artifactId>
|
||||
<classifier>${djl.platform.linux-x86_64}</classifier>
|
||||
<version>2.5.1</version>
|
||||
<artifactId>pytorch-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.linux-aarch64}</classifier>
|
||||
<version>2.7.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ai.djl.tensorflow</groupId>
|
||||
<artifactId>tensorflow-native-cpu</artifactId>
|
||||
<classifier>${javacv.platform.linux-arm64}</classifier>
|
||||
<scope>runtime</scope>
|
||||
<version>2.16.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl.mxnet</groupId>
|
||||
<artifactId>mxnet-native-mkl</artifactId>
|
||||
<classifier>${javacv.platform.linux-arm64}</classifier>
|
||||
<scope>runtime</scope>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- macOS M系列 平台 (保留对应平台的配置,可以减小包大小)-->
|
||||
<dependency>
|
||||
@@ -244,7 +286,7 @@
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.osx-aarch64}</classifier>
|
||||
<version>2.5.1</version>
|
||||
<version>2.7.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ClsDemo {
|
||||
|
||||
public ClsModel getModel(){
|
||||
ClsModelConfig config = new ClsModelConfig();
|
||||
//实例分割模型,切换模型需要同时修改modelEnum及modelPath
|
||||
//切换模型需要同时修改modelEnum及modelPath
|
||||
config.setModelEnum(ClsModelEnum.YOLOV8);
|
||||
//模型所在路径,synset.txt也需要放在同目录下
|
||||
config.setModelPath("/Users/wenjie/Documents/develop/model/vision/cls/yolo11m-cls.onnx");
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package smartai.examples.vision;
|
||||
|
||||
import ai.djl.modality.cv.Image;
|
||||
|
||||
import cn.smartjavaai.common.cv.SmartImageFactory;
|
||||
import cn.smartjavaai.common.entity.DetectionResponse;
|
||||
import cn.smartjavaai.common.entity.R;
|
||||
import cn.smartjavaai.common.enums.DeviceEnum;
|
||||
import cn.smartjavaai.common.utils.ImageUtils;
|
||||
import cn.smartjavaai.zeroshot.config.ZeroDetConfig;
|
||||
import cn.smartjavaai.zeroshot.enums.ZeroDetModelEnum;
|
||||
import cn.smartjavaai.zeroshot.model.ZeroDetModel;
|
||||
import cn.smartjavaai.zeroshot.model.ZeroDetModelFactory;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* 零样本目标检测
|
||||
* @author dwj
|
||||
*/
|
||||
@Slf4j
|
||||
public class ZeroShotObjectDetectionDemo {
|
||||
|
||||
|
||||
//设备类型
|
||||
public static DeviceEnum device = DeviceEnum.CPU;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeAll() throws IOException {
|
||||
//修改缓存路径
|
||||
// Config.setCachePath("/Users/xxx/smartjavaai_cache");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取零样本目标检测模型
|
||||
*/
|
||||
public ZeroDetModel getModel(){
|
||||
ZeroDetConfig config = new ZeroDetConfig();
|
||||
//零样本目标检测模型,切换模型需要同时修改modelEnum及modelPath
|
||||
config.setModelEnum(ZeroDetModelEnum.OWLV2_BASE_PATCH16);
|
||||
//模型所在路径
|
||||
config.setModelPath("/Users/wenjie/Documents/develop/model/vision/zero/owlv2-base-patch16");
|
||||
config.setDevice(device);
|
||||
//置信度阈值
|
||||
config.setThreshold(0.5f);
|
||||
return ZeroDetModelFactory.getInstance().getModel(config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 零样本目标检测
|
||||
* 特性:
|
||||
* 1、零样本检测能力:无需针对特定类别进行训练,可直接通过文本查询检测新类别物体
|
||||
* 2、开放词汇识别:能够识别训练时未见过的类别名称,突破传统检测模型的类别限制
|
||||
* 3、多查询支持:支持同时使用多个文本查询进行目标检测,提高检测效率
|
||||
*/
|
||||
@Test
|
||||
public void zeroDetection(){
|
||||
try {
|
||||
ZeroDetModel detectorModel = getModel();
|
||||
//创建Image对象,可以从文件、url、InputStream创建、BufferedImage、Base64创建,具体使用方法可以查看文档
|
||||
Image image = SmartImageFactory.getInstance().fromFile(Paths.get("src/main/resources/zero/000000039769.jpg"));
|
||||
//输入图片以及条件
|
||||
R<DetectionResponse> result = detectorModel.detect(image, new String[]{"cat","remote control"});
|
||||
if(result.isSuccess()){
|
||||
log.info("零样本目标检测结果:{}", JSONObject.toJSONString(result.getData()));
|
||||
}else{
|
||||
log.info("零样本目标检测失败:{}", result.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 零样本目标检测并绘制检测结果
|
||||
* 特性:
|
||||
* 1、零样本检测能力:无需针对特定类别进行训练,可直接通过文本查询检测新类别物体
|
||||
* 2、开放词汇识别:能够识别训练时未见过的类别名称,突破传统检测模型的类别限制
|
||||
* 3、多查询支持:支持同时使用多个文本查询进行目标检测,提高检测效率
|
||||
*/
|
||||
@Test
|
||||
public void zeroDetectionAndDraw() {
|
||||
try {
|
||||
ZeroDetModel detectorModel = getModel();
|
||||
String[] candidates = new String[]{"cat","remote control"};
|
||||
//保存绘制后图片以及返回检测结果
|
||||
R<DetectionResponse> result = detectorModel.detectAndDraw(candidates, "src/main/resources/zero/000000039769.jpg","output/cat_detected.png");
|
||||
if(result.isSuccess()){
|
||||
log.info("零样本目标检测结果:{}", JSONObject.toJSONString(result.getData()));
|
||||
}else{
|
||||
log.info("零样本目标检测失败:{}", result.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 零样本目标检测并绘制检测结果
|
||||
* 特性:
|
||||
* 1、零样本检测能力:无需针对特定类别进行训练,可直接通过文本查询检测新类别物体
|
||||
* 2、开放词汇识别:能够识别训练时未见过的类别名称,突破传统检测模型的类别限制
|
||||
* 3、多查询支持:支持同时使用多个文本查询进行目标检测,提高检测效率
|
||||
*/
|
||||
@Test
|
||||
public void zeroDetectionAndDraw2(){
|
||||
try {
|
||||
ZeroDetModel detectorModel = getModel();
|
||||
//创建Image对象,可以从文件、url、InputStream创建、BufferedImage、Base64创建,具体使用方法可以查看文档
|
||||
Image image = SmartImageFactory.getInstance().fromFile(Paths.get("src/main/resources/zero/000000039769.jpg"));
|
||||
String[] candidates = new String[]{"cat","remote control"};
|
||||
R<DetectionResponse> result = detectorModel.detectAndDraw(image, candidates);
|
||||
if(result.isSuccess()){
|
||||
log.info("零样本目标检测结果:{}", JSONObject.toJSONString(result.getData()));
|
||||
//保存图片
|
||||
ImageUtils.save(result.getData().getDrawnImage(), "output/cat_detected.png");
|
||||
}else{
|
||||
log.info("零样本目标检测失败:{}", result.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user