mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-12 20:58:51 +00:00
1、人脸模块:新增小视科技(MiniVision)活体检测模型
2、人脸模块:新增阿里通义工作室活体检测模型 3、人脸模块:新增2个表情识别模型 4、人脸模块:新增InsightFace、ElasticFace人脸识别模型 5、人脸模块:新增Seetaface6质量评估模型 6、目标检测模块:开放更多自定义模型参数 7、人脸模块:支持base64图片 8、实现接口 AutoCloseable,支持资源的自动释放 9、OCR模块:解决加方向矫正后无法连续识别bug 10、人脸模块:解决人脸更新后缓存问题 11、优化部分功能
This commit is contained in:
@@ -5,6 +5,9 @@ import cn.smartjavaai.objectdetection.constant.DetectorConstant;
|
||||
import cn.smartjavaai.objectdetection.enums.DetectorModelEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 目标检测模型参数配置
|
||||
*
|
||||
@@ -41,6 +44,11 @@ public class DetectorModelConfig {
|
||||
*/
|
||||
private int maxBox;
|
||||
|
||||
/**
|
||||
* 个性化配置
|
||||
*/
|
||||
private Map<String, Object> customParams = new HashMap<>();
|
||||
|
||||
public DetectorModelConfig() {
|
||||
}
|
||||
|
||||
@@ -52,4 +60,20 @@ public class DetectorModelConfig {
|
||||
public DetectorModelConfig(DetectorModelEnum modelEnum) {
|
||||
this.modelEnum = modelEnum;
|
||||
}
|
||||
|
||||
public <T> T getCustomParam(String key, Class<T> clazz) {
|
||||
Object value = customParams.get(key);
|
||||
if (value == null) return null;
|
||||
return clazz.cast(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加个性化配置项
|
||||
*/
|
||||
public void putCustomParam(String key, Object value) {
|
||||
if (customParams == null) {
|
||||
customParams = new HashMap<>();
|
||||
}
|
||||
customParams.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class DJLModelCriteriaBuilder implements CriteriaBuilderStrategy {
|
||||
.optArgument("threshold", config.getThreshold() > 0 ? config.getThreshold() : DetectorConstant.DEFAULT_THRESHOLD)
|
||||
.optModelUrls(DJL_MODEL_PREFIX + config.getModelEnum().getModelUri())
|
||||
.optDevice(device)
|
||||
//.optOption("ortDevice", "TensorRT")
|
||||
.optProgress(new ProgressBar())
|
||||
.build();
|
||||
return criteria;
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package cn.smartjavaai.objectdetection.criteria;
|
||||
|
||||
import ai.djl.Device;
|
||||
import ai.djl.modality.cv.Image;
|
||||
import ai.djl.modality.cv.output.DetectedObjects;
|
||||
import ai.djl.modality.cv.translator.YoloV8TranslatorFactory;
|
||||
import ai.djl.repository.zoo.Criteria;
|
||||
import ai.djl.training.util.ProgressBar;
|
||||
import cn.smartjavaai.common.enums.DeviceEnum;
|
||||
import cn.smartjavaai.objectdetection.constant.DetectorConstant;
|
||||
import cn.smartjavaai.objectdetection.config.DetectorModelConfig;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* YOLO模型Criteria 构建器
|
||||
@@ -18,16 +23,25 @@ import java.nio.file.Paths;
|
||||
public class YoloCriteriaBuilder implements CriteriaBuilderStrategy {
|
||||
@Override
|
||||
public Criteria<Image, DetectedObjects> buildCriteria(DetectorModelConfig config) {
|
||||
Device device = null;
|
||||
if(!Objects.isNull(config.getDevice())){
|
||||
device = config.getDevice() == DeviceEnum.CPU ? Device.cpu() : Device.gpu();
|
||||
}
|
||||
|
||||
Map<String, Object> customParams = getDefaultConfig();
|
||||
// 合并用户自定义参数(如有重复,覆盖默认默认值)
|
||||
if (config.getCustomParams() != null) {
|
||||
customParams.putAll(config.getCustomParams());
|
||||
}
|
||||
|
||||
Criteria.Builder criteriaBuilder = Criteria.builder()
|
||||
.setTypes(Image.class, DetectedObjects.class)
|
||||
//.optModelUrls("/Users/wenjie/Documents/develop/face_model/yolo")
|
||||
.optModelPath(Paths.get(config.getModelPath()))
|
||||
.optEngine("OnnxRuntime")
|
||||
.optArgument("width", 640) //将输入图像的宽度缩放为 640 像素
|
||||
.optArgument("height", 640)
|
||||
.optArgument("resize", true)
|
||||
.optArgument("toTensor", true)
|
||||
.optArgument("applyRatio", true)
|
||||
//.optOption("ortDevice", "TensorRT")
|
||||
.optArguments(customParams)
|
||||
.optDevice(device)
|
||||
.optTranslatorFactory(new YoloV8TranslatorFactory())
|
||||
.optProgress(new ProgressBar())
|
||||
.optArgument("threshold", config.getThreshold() > 0 ? config.getThreshold() : DetectorConstant.DEFAULT_THRESHOLD);
|
||||
@@ -37,4 +51,15 @@ public class YoloCriteriaBuilder implements CriteriaBuilderStrategy {
|
||||
Criteria<Image, DetectedObjects> criteria = criteriaBuilder.build();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public Map<String, Object> getDefaultConfig(){
|
||||
Map<String, Object> arguments = new HashMap<>();
|
||||
// 添加默认参数
|
||||
arguments.put("width", 640);
|
||||
arguments.put("height", 640);
|
||||
arguments.put("resize", true);
|
||||
arguments.put("toTensor", true);
|
||||
arguments.put("applyRatio", true);
|
||||
return arguments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,6 @@ public class DetectorModel implements AutoCloseable{
|
||||
|
||||
private ZooModel<Image, DetectedObjects> model;
|
||||
|
||||
//private Predictor<Image, DetectedObjects> predictor;
|
||||
|
||||
|
||||
|
||||
private ObjectPool<Predictor<Image, DetectedObjects>> predictorPool;
|
||||
|
||||
public void loadModel(DetectorModelConfig config){
|
||||
@@ -193,12 +189,23 @@ public class DetectorModel implements AutoCloseable{
|
||||
|
||||
|
||||
/**
|
||||
* 显式释放资源(必须调用!)
|
||||
* 显式释放资源
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
if (predictorPool != null) {
|
||||
predictorPool.close();
|
||||
try {
|
||||
if (predictorPool != null) {
|
||||
predictorPool.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 predictorPool 失败", e);
|
||||
}
|
||||
try {
|
||||
if (model != null) {
|
||||
model.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 model 失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user