- 【人脸检测】新增6个模型(MTCNN、YOLOV5、RetinaFace小尺寸版),大幅提升性能

- 【人脸识别】新增Seetaface6轻量模型
- 【目标检测】支持视频流目标检测(rtsp、视频文件等)
- 【目标检测】支持tensorflow2目标检测模型
- 【目标检测】新增行人检测模型(yolo-person)
- 【通用视觉】新增4个动作识别模型
- 【通用视觉】新增语义分割模型
- 【通用视觉】新增5个实例分割模型(含yolov8-seg、yolov11-seg)
- 【通用视觉】新增yolo-obb11旋转框检测(含yolov11-obb)
- 【通用视觉】新增5个姿态估计模型(含yolov8-pose、yolov11-pose)
This commit is contained in:
dengwenjie
2025-09-07 17:19:19 +08:00
parent 2b044fda29
commit a8e7ce6c4e
102 changed files with 4473 additions and 1368 deletions

View File

@@ -55,11 +55,7 @@
<artifactId>commons-io</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
@@ -73,11 +69,6 @@
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
@@ -101,7 +92,7 @@
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-jni</artifactId>
<version>2.7.1-0.34.0</version>
<version>2.5.1-0.32.0</version>
<scope>runtime</scope>
</dependency>
@@ -138,7 +129,7 @@
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-cpu</artifactId>
<classifier>${djl.platform.windows-x86_64}</classifier>
<version>2.7.1</version>
<version>2.5.1</version>
<scope>runtime</scope>
</dependency>
@@ -176,9 +167,18 @@
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-cpu</artifactId>
<classifier>${djl.platform.linux-x86_64}</classifier>
<version>2.7.1</version>
<version>2.5.1</version>
<scope>runtime</scope>
</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>
<scope>runtime</scope>
</dependency>
<!-- macOS M系列 平台 (保留对应平台的配置,可以减小包大小)-->
@@ -213,11 +213,13 @@
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-cpu</artifactId>
<classifier>${djl.platform.osx-aarch64}</classifier>
<version>2.7.1</version>
<version>2.5.1</version>
<scope>runtime</scope>
</dependency>
<!-- linux aarch64 平台 (保留对应平台的配置,可以减小包大小)-->
<dependency>
<groupId>org.bytedeco</groupId>
@@ -247,22 +249,6 @@
<classifier>${javacv.platform.linux-arm64}</classifier>
</dependency>
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-cpu-precxx11</artifactId>
<classifier>${djl.platform.linux-aarch64}</classifier>
<version>2.5.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-native-cpu</artifactId>
<classifier>linux-aarch64</classifier>
<scope>runtime</scope>
<version>2.7.1</version>
</dependency>
</dependencies>
@@ -294,16 +280,10 @@
<repositories>
<repository>
<id>aliyunmaven</id>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>

View File

@@ -1,118 +0,0 @@
/*
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package smartai.examples.face;
import ai.djl.ModelException;
import ai.djl.inference.Predictor;
import ai.djl.modality.Classifications;
import ai.djl.modality.Input;
import ai.djl.modality.Output;
import ai.djl.modality.cv.Image;
import ai.djl.ndarray.NDList;
import ai.djl.repository.zoo.Criteria;
import ai.djl.repository.zoo.ZooModel;
import ai.djl.translate.NoBatchifyTranslator;
import ai.djl.translate.TranslateException;
import ai.djl.translate.TranslatorContext;
import ai.djl.util.JsonUtils;
import ai.djl.util.Utils;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PythonTranslator implements NoBatchifyTranslator<byte[], Classifications> {
private ZooModel<Input, Output> model;
private Predictor<Input, Output> predictor;
@Override
public void prepare(TranslatorContext ctx) throws ModelException, IOException {
if (predictor == null) {
Criteria<Input, Output> criteria =
Criteria.builder()
.setTypes(Input.class, Output.class)
.optModelPath(Paths.get("src/test/python"))
.optEngine("Python")
.build();
model = criteria.loadModel();
predictor = model.newPredictor();
}
}
// @Override
// public NDList processInput(TranslatorContext ctx, String url)
// throws IOException, TranslateException {
// Input input = new Input();
// try (InputStream is = new URL(url).openStream()) {
// input.add("data", Utils.toByteArray(is));
// }
// input.addProperty("Content-Type", "image/jpeg");
// // calling preprocess() function in model.py
// input.addProperty("handler", "preprocess");
// Output output = predictor.predict(input);
// if (output.getCode() != 200) {
// throw new TranslateException("Python preprocess() failed: " + output.getMessage());
// }
//
// return output.getDataAsNDList(ctx.getNDManager());
// }
@Override
public NDList processInput(TranslatorContext ctx, byte[] image)
throws IOException, TranslateException {
Input input = new Input();
input.add("data", image);
input.addProperty("Content-Type", "image/jpeg");
// calling preprocess() function in model.py
input.addProperty("handler", "preprocess");
Output output = predictor.predict(input);
if (output.getCode() != 200) {
throw new TranslateException("Python preprocess() failed: " + output.getMessage());
}
return output.getDataAsNDList(ctx.getNDManager());
}
@Override
public Classifications processOutput(TranslatorContext ctx, NDList list)
throws TranslateException {
Input input = new Input();
input.add("data", list);
// calling postprocess() function in processing.py
input.addProperty("handler", "postprocess");
Output output = predictor.predict(input);
if (output.getCode() != 200) {
throw new TranslateException("Python postprocess() failed: " + output.getMessage());
}
String json = output.getData().getAsString();
System.out.println("json:" + json);
return null;
}
public void close() {
if (predictor != null) {
predictor.close();
model.close();
predictor = null;
model = null;
}
}
}

View File

@@ -1,99 +0,0 @@
package smartai.examples.face;
import ai.djl.Application;
import ai.djl.Device;
import ai.djl.MalformedModelException;
import ai.djl.inference.Predictor;
import ai.djl.modality.Classifications;
import ai.djl.modality.audio.Audio;
import ai.djl.modality.audio.AudioFactory;
import ai.djl.modality.audio.translator.SpeechRecognitionTranslatorFactory;
import ai.djl.repository.Artifact;
import ai.djl.repository.MRL;
import ai.djl.repository.zoo.Criteria;
import ai.djl.repository.zoo.ModelNotFoundException;
import ai.djl.repository.zoo.ModelZoo;
import ai.djl.repository.zoo.ZooModel;
import ai.djl.translate.TranslateException;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
/**
* @author dwj
* @date 2025/7/29
*/
@Slf4j
public class Test {
public static void main(String[] args) throws ModelNotFoundException, MalformedModelException, IOException, TranslateException {
// PythonTranslator translator = new PythonTranslator();
// Criteria<byte[], Classifications> criteria =
// Criteria.builder()
// .setTypes(byte[].class, Classifications.class)
// .optModelPath(Paths.get("/Users/wenjie/Documents/develop/model/arcfaceresnet100-11-int8.onnx"))
// .optEngine("OnnxRuntime")
// .optTranslator(translator)
// .build();
// String path = "/Users/wenjie/Downloads/facetest/jsy.jpg";
// try (ZooModel<byte[], Classifications> model = criteria.loadModel();
// Predictor<byte[], Classifications> predictor = model.newPredictor()) {
// byte[] data = Files.readAllBytes(Paths.get(path));
// Classifications ret = predictor.predict(data);
// System.out.println(ret);
// }
//
// // unload python model
// translator.close();
// Load model.
// Wav2Vec2 model is a speech model that accepts a float array corresponding to the raw
// waveform of the speech signal.
// String url = "/Users/wenjie/Downloads/20210601_u2++_conformer_exp/final.pt";
// Criteria<Audio, String> criteria =
// Criteria.builder()
// .setTypes(Audio.class, String.class)
//// .optModelUrls(url)
// .optModelPath(Paths.get(url))
// .optDevice(Device.cpu()) // torchscript model only support CPU
// .optTranslatorFactory(new SpeechRecognitionTranslatorFactory())
//// .optModelName("data.pkl")
// .optEngine("PyTorch")
// .build();
//
// // Read in audio file
// String wave = "https://resources.djl.ai/audios/speech.wav";
// Audio audio = AudioFactory.newInstance().fromUrl(wave);
// try (ZooModel<Audio, String> model = criteria.loadModel();
// Predictor<Audio, String> predictor = model.newPredictor()) {
// String result = predictor.predict(audio);
// log.info("Result: {}", result);
// }
boolean withArtifacts =
args.length > 0 && ("--artifact".equals(args[0]) || "-a".equals(args[0]));
if (!withArtifacts) {
log.info("============================================================");
log.info("user ./gradlew listModel --args='-a' to show artifact detail");
log.info("============================================================");
}
// Map<Application, List<Artifact>> models = ModelZoo.listModels();
// for (Map.Entry<Application, List<Artifact>> entry : models.entrySet()) {
// String appName = entry.getKey().toString();
// for (Artifact artifact : entry.getValue()) {
// if (withArtifacts) {
// log.info("{} djl://{}", appName, artifact);
// } else {
// log.info("{} {}", appName, artifact);
// }
// }
// }
}
}

View File

@@ -1,25 +0,0 @@
package smartai.examples.face;
import cn.smartjavaai.common.utils.VideoUtils;
import org.bytedeco.ffmpeg.global.avcodec;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FFmpegFrameRecorder;
/**
* 视频预处理
* @author dwj
* @date 2025/7/17
*/
public class VideoDemo {
public static void main(String[] args) {
try {
VideoUtils.rotateVideo("/Users/wenjie/Downloads/girl.mp4", "/Users/wenjie/Downloads/girl_rotate.mp4", 180,"mp4", avcodec.AV_CODEC_ID_H264);
} catch (FFmpegFrameRecorder.Exception e) {
throw new RuntimeException(e);
} catch (FFmpegFrameGrabber.Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -30,6 +30,7 @@ import java.util.List;
/**
* 人脸属性检测demo
* 模型下载地址https://pan.baidu.com/s/10l22x5fRz_gwLr8EAHa1Jg?pwd=1234 提取码: 1234
* 文档地址http://doc.smartjavaai.cn/
* @author dwj
*/
@Slf4j
@@ -91,23 +92,6 @@ public class FaceAttributeDetDemo {
}
}
/**
* 图片多人脸属性检测(基于已检测出的人脸区域和关键点)
*/
@Test
public void testFaceAttributeDetect3(){
try {
FaceAttributeModel faceAttributeModel = getFaceAttributeModel();
FaceAttribute faceAttribute = faceAttributeModel.detectTopFace("src/main/resources/iu_1.jpg");
log.info("人脸属性检测结果:{}", JSONObject.toJSONString(faceAttribute));
} catch (Exception e) {
e.printStackTrace();
}
//人脸检测
}
/**
* 图片单人脸人脸属性检测(基于已检测出的人脸区域和关键点)

View File

@@ -48,6 +48,8 @@ import java.util.List;
/**
* 表情识别demo
* 支持识别7种表情neutral中性、happy高兴、sad悲伤、surprise惊讶、fear恐惧、disgust厌恶、anger愤怒
* 模型下载地址https://pan.baidu.com/s/10l22x5fRz_gwLr8EAHa1Jg?pwd=1234 提取码: 1234
* 文档地址http://doc.smartjavaai.cn/
* @author dwj
*/
@Slf4j

View File

@@ -39,9 +39,8 @@ import java.nio.file.Paths;
/**
* 人脸检测模型demo
* 支持系统windows 64位linux 64位, macos M系列
* 支持功能:人脸检测
* 模型下载地址https://pan.baidu.com/s/1d2YlJ2YOdGn3Y-AegyAhmQ?pwd=1234 提取码: 1234
* 文档地址http://doc.smartjavaai.cn/
* @author dwj
*/
@Slf4j

View File

@@ -32,12 +32,10 @@ import java.io.IOException;
import java.util.List;
/**
* FaceNet人脸算法模型demo
* 支持系统windows 64位linux 64位macOS M系列芯片
* 支持功能人脸特征提取、人脸比对11、人脸比对1N、人脸注册
* 人脸识别模型demo
* 模型下载地址https://pan.baidu.com/s/10l22x5fRz_gwLr8EAHa1Jg?pwd=1234 提取码: 1234
* 文档地址http://doc.smartjavaai.cn/
* @author dwj
* @date 2025/4/11
*/
@Slf4j
public class FaceRecDemo {
@@ -142,8 +140,8 @@ public class FaceRecDemo {
*/
public FaceRecModel getHighSpeedFaceRecModel(){
FaceRecConfig config = new FaceRecConfig();
//高精度模型,速度慢
config.setModelEnum(FaceRecModelEnum.SEETA_FACE6_MODEL);
//模型枚举
config.setModelEnum(FaceRecModelEnum.SEETA_FACE6_LIGHT_MODEL);
//模型路径请下载模型并替换为本地路径https://pan.baidu.com/s/10l22x5fRz_gwLr8EAHa1Jg?pwd=1234 提取码: 1234
config.setModelPath("/Users/xxx/Documents/develop/model/sf3.0_models");
//裁剪人脸如果图片已经是裁剪过的则请将此参数设置为false

View File

@@ -54,8 +54,8 @@ import java.util.List;
/**
* 静态活体检测demo
* 模型下载地址https://pan.baidu.com/s/10l22x5fRz_gwLr8EAHa1Jg?pwd=1234 提取码: 1234
* 文档地址http://doc.smartjavaai.cn/
* @author dwj
* @date 2025/5/1
*/
@Slf4j
public class LivenessDetDemo {

View File

@@ -36,6 +36,7 @@ import java.nio.file.Paths;
/**
* 人脸质量评估 demo
* 模型下载地址https://pan.baidu.com/s/10l22x5fRz_gwLr8EAHa1Jg?pwd=1234 提取码: 1234
* 文档地址http://doc.smartjavaai.cn/
* @author dwj
*/
@Slf4j