mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-10 03:28:49 +00:00
【人脸识别】 新增多种人脸识别模型
【底层优化】 支持自由选择 OpenCV 或 BufferedImage 作为图像引擎 【通用图像】 全部模型启用 Image 输入,支持各类图片格式与 Image 的互转 【模型管理】 优化模型生命周期,关闭后可重新创建 【人脸识别】 支持在人脸查询结果中绘制姓名标注 【人脸检测】 新增人脸裁剪功能 【修复】 修复若干已知问题,提升系统稳定性
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<version>1.0.24</version>
|
||||
<version>1.0.25</version>
|
||||
<name>translate</name>
|
||||
<description>SmartJavaAI</description>
|
||||
<url>https://github.com/geekwenjie/SmartJavaAI</url>
|
||||
|
||||
@@ -90,6 +90,7 @@ public class TranslationModelFactory {
|
||||
throw new TranslationException(e);
|
||||
}
|
||||
model.loadModel(config);
|
||||
model.setFromFactory(true);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -102,4 +103,26 @@ public class TranslationModelFactory {
|
||||
log.debug("缓存目录:{}", Config.getCachePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭所有已加载的模型
|
||||
*/
|
||||
public void closeAll() {
|
||||
modelMap.values().forEach(model -> {
|
||||
try {
|
||||
model.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
modelMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除缓存的模型
|
||||
* @param modelEnum
|
||||
*/
|
||||
public static void removeFromCache(TranslationModeEnum modelEnum) {
|
||||
modelMap.remove(modelEnum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import cn.smartjavaai.translation.config.NllbSearchConfig;
|
||||
import cn.smartjavaai.translation.entity.GreedyBatchTensorList;
|
||||
import cn.smartjavaai.translation.entity.TranslateParam;
|
||||
import cn.smartjavaai.translation.exception.TranslationException;
|
||||
import cn.smartjavaai.translation.factory.TranslationModelFactory;
|
||||
import cn.smartjavaai.translation.model.translator.NllbDecoder2Translator;
|
||||
import cn.smartjavaai.translation.model.translator.NllbDecoderTranslator;
|
||||
import cn.smartjavaai.translation.model.translator.NllbEncoderTranslator;
|
||||
@@ -274,6 +275,9 @@ public class NllbModel implements TranslationModel{
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if (fromFactory) {
|
||||
TranslationModelFactory.removeFromCache(config.getModelEnum());
|
||||
}
|
||||
try {
|
||||
if (nllbModel != null) {
|
||||
nllbModel.close();
|
||||
@@ -310,4 +314,14 @@ public class NllbModel implements TranslationModel{
|
||||
log.warn("关闭 decode2PredictorPool 失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fromFactory = false;
|
||||
|
||||
@Override
|
||||
public void setFromFactory(boolean fromFactory) {
|
||||
this.fromFactory = fromFactory;
|
||||
}
|
||||
public boolean isFromFactory() {
|
||||
return fromFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import cn.smartjavaai.translation.entity.BeamBatchTensorList;
|
||||
import cn.smartjavaai.translation.entity.GreedyBatchTensorList;
|
||||
import cn.smartjavaai.translation.entity.TranslateParam;
|
||||
import cn.smartjavaai.translation.exception.TranslationException;
|
||||
import cn.smartjavaai.translation.factory.TranslationModelFactory;
|
||||
import cn.smartjavaai.translation.model.translator.NllbDecoder2Translator;
|
||||
import cn.smartjavaai.translation.model.translator.NllbDecoderTranslator;
|
||||
import cn.smartjavaai.translation.model.translator.NllbEncoderTranslator;
|
||||
@@ -403,6 +404,9 @@ public class OpusMtModel implements TranslationModel{
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if (fromFactory) {
|
||||
TranslationModelFactory.removeFromCache(config.getModelEnum());
|
||||
}
|
||||
try {
|
||||
if (model != null) {
|
||||
model.close();
|
||||
@@ -439,4 +443,14 @@ public class OpusMtModel implements TranslationModel{
|
||||
log.warn("关闭 decode2PredictorPool 失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fromFactory = false;
|
||||
|
||||
@Override
|
||||
public void setFromFactory(boolean fromFactory) {
|
||||
this.fromFactory = fromFactory;
|
||||
}
|
||||
public boolean isFromFactory() {
|
||||
return fromFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ public interface TranslationModel extends AutoCloseable{
|
||||
}
|
||||
|
||||
|
||||
|
||||
default void setFromFactory(boolean fromFactory){
|
||||
throw new UnsupportedOperationException("默认不支持该功能");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user