mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-14 05:38:50 +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:
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cn.smartjavaai</groupId>
|
||||
<artifactId>smartjavaai-parent</artifactId>
|
||||
<version>1.0.17</version>
|
||||
<version>1.0.19</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>smartjavaai-ocr</artifactId>
|
||||
@@ -20,7 +20,7 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<version>1.0.17</version>
|
||||
<version>1.0.19</version>
|
||||
<name>smartjavaai-ocr</name>
|
||||
<description>SmartJavaAI</description>
|
||||
<url>https://github.com/geekwenjie/SmartJavaAI</url>
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
* OCR 通用检测模型
|
||||
* @author dwj
|
||||
*/
|
||||
public interface OcrCommonDetModel {
|
||||
public interface OcrCommonDetModel extends AutoCloseable{
|
||||
|
||||
/**
|
||||
* 加载模型
|
||||
|
||||
@@ -53,6 +53,8 @@ public class PpOCRV5DetModel implements OcrCommonDetModel {
|
||||
|
||||
private ObjectPool<Predictor<Image, NDList>> detPredictorPool;
|
||||
|
||||
private ZooModel<Image, NDList> detectionModel;
|
||||
|
||||
private OcrDetModelConfig config;
|
||||
|
||||
@Override
|
||||
@@ -77,7 +79,7 @@ public class PpOCRV5DetModel implements OcrCommonDetModel {
|
||||
.build();
|
||||
|
||||
try{
|
||||
ZooModel detectionModel = ModelZoo.loadModel(detCriteria);
|
||||
detectionModel = ModelZoo.loadModel(detCriteria);
|
||||
// 创建池子:每个线程独享 Predictor
|
||||
this.detPredictorPool = new GenericObjectPool<>(new PredictorFactory<>(detectionModel));
|
||||
log.debug("当前设备: " + detectionModel.getNDManager().getDevice());
|
||||
@@ -198,4 +200,22 @@ public class PpOCRV5DetModel implements OcrCommonDetModel {
|
||||
throw new OcrException("导出图片失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
try {
|
||||
if (detPredictorPool != null) {
|
||||
detPredictorPool.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 predictorPool 失败", e);
|
||||
}
|
||||
try {
|
||||
if (detectionModel != null) {
|
||||
detectionModel.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 model 失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* OCR 文本方向分类模型
|
||||
* @author dwj
|
||||
*/
|
||||
public interface OcrDirectionModel {
|
||||
public interface OcrDirectionModel extends AutoCloseable{
|
||||
|
||||
/**
|
||||
* 加载模型
|
||||
|
||||
@@ -64,6 +64,8 @@ public class PPOCRMobileV2Model implements OcrDirectionModel {
|
||||
|
||||
private OcrCommonDetModel detModel;
|
||||
|
||||
private ZooModel<Image, DirectionInfo> model;
|
||||
|
||||
|
||||
@Override
|
||||
public void loadModel(DirectionModelConfig config){
|
||||
@@ -86,7 +88,7 @@ public class PPOCRMobileV2Model implements OcrDirectionModel {
|
||||
.optProgress(new ProgressBar())
|
||||
.build();
|
||||
try{
|
||||
ZooModel model = ModelZoo.loadModel(criteria);
|
||||
model = ModelZoo.loadModel(criteria);
|
||||
// 创建池子:每个线程独享 Predictor
|
||||
this.predictorPool = new GenericObjectPool<>(new PredictorFactory<>(model));
|
||||
log.debug("当前设备: " + model.getNDManager().getDevice());
|
||||
@@ -100,6 +102,7 @@ public class PPOCRMobileV2Model implements OcrDirectionModel {
|
||||
OcrDetModelConfig detModelConfig = new OcrDetModelConfig();
|
||||
detModelConfig.setModelEnum(config.getDetModelEnum());
|
||||
detModelConfig.setDetModelPath(config.getDetModelPath());
|
||||
detModelConfig.setDevice(config.getDevice());
|
||||
detModel = OcrModelFactory.getInstance().getDetModel(detModelConfig);
|
||||
}
|
||||
}
|
||||
@@ -215,6 +218,19 @@ public class PPOCRMobileV2Model implements OcrDirectionModel {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new OcrException("OCR检测错误", e);
|
||||
}finally {
|
||||
if (predictor != null) {
|
||||
try {
|
||||
predictorPool.returnObject(predictor); //归还
|
||||
} catch (Exception e) {
|
||||
log.warn("归还Predictor失败", e);
|
||||
try {
|
||||
predictor.close(); // 归还失败才销毁
|
||||
} catch (Exception ex) {
|
||||
log.error("关闭Predictor失败", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ocrItemList;
|
||||
}
|
||||
@@ -287,4 +303,29 @@ public class PPOCRMobileV2Model implements OcrDirectionModel {
|
||||
throw new OcrException("导出图片失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
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);
|
||||
}
|
||||
try {
|
||||
if (detModel != null) {
|
||||
detModel.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 model 失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
* OCR 通用识别模型
|
||||
* @author dwj
|
||||
*/
|
||||
public interface OcrCommonRecModel {
|
||||
public interface OcrCommonRecModel extends AutoCloseable{
|
||||
|
||||
/**
|
||||
* 加载模型
|
||||
|
||||
@@ -67,6 +67,8 @@ public class PpOCRV5RecModel implements OcrCommonRecModel {
|
||||
|
||||
private OcrDirectionModel directionModel;
|
||||
|
||||
private ZooModel<Image, String> recognitionModel;
|
||||
|
||||
@Override
|
||||
public void loadModel(OcrRecModelConfig config){
|
||||
if(StringUtils.isBlank(config.getRecModelPath())){
|
||||
@@ -88,7 +90,7 @@ public class PpOCRV5RecModel implements OcrCommonRecModel {
|
||||
.optDevice(device)
|
||||
.build();
|
||||
try{
|
||||
ZooModel recognitionModel = ModelZoo.loadModel(recCriteria);
|
||||
recognitionModel = ModelZoo.loadModel(recCriteria);
|
||||
this.recPredictorPool = new GenericObjectPool<>(new PredictorFactory<>(recognitionModel));
|
||||
log.debug("当前设备: " + recognitionModel.getNDManager().getDevice());
|
||||
log.debug("当前引擎: " + Engine.getInstance().getEngineName());
|
||||
@@ -102,6 +104,7 @@ public class PpOCRV5RecModel implements OcrCommonRecModel {
|
||||
OcrDetModelConfig detModelConfig = new OcrDetModelConfig();
|
||||
detModelConfig.setModelEnum(config.getDetModelEnum());
|
||||
detModelConfig.setDetModelPath(config.getDetModelPath());
|
||||
detModelConfig.setDevice(config.getDevice());
|
||||
detModel = OcrModelFactory.getInstance().getDetModel(detModelConfig);
|
||||
}
|
||||
|
||||
@@ -110,6 +113,7 @@ public class PpOCRV5RecModel implements OcrCommonRecModel {
|
||||
DirectionModelConfig directionModelConfig = new DirectionModelConfig();
|
||||
directionModelConfig.setModelEnum(config.getDirectionModelEnum());
|
||||
directionModelConfig.setModelPath(config.getDirectionModelPath());
|
||||
directionModelConfig.setDevice(config.getDevice());
|
||||
directionModel = OcrModelFactory.getInstance().getDirectionModel(directionModelConfig);
|
||||
}
|
||||
}
|
||||
@@ -320,4 +324,36 @@ public class PpOCRV5RecModel implements OcrCommonRecModel {
|
||||
throw new OcrException("导出图片失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
try {
|
||||
if (recPredictorPool != null) {
|
||||
recPredictorPool.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 predictorPool 失败", e);
|
||||
}
|
||||
try {
|
||||
if (detModel != null) {
|
||||
detModel.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 model 失败", e);
|
||||
}
|
||||
try {
|
||||
if (directionModel != null) {
|
||||
directionModel.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 model 失败", e);
|
||||
}
|
||||
try {
|
||||
if (recognitionModel != null) {
|
||||
recognitionModel.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("关闭 model 失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user