mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-10 03:28:49 +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:
7
examples/translation-example/.gitignore
vendored
Normal file
7
examples/translation-example/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
.idea
|
||||
.idea/
|
||||
target
|
||||
log
|
||||
*.iml
|
||||
/.settings/
|
||||
/logging.file_IS_UNDEFINED/
|
||||
40
examples/translation-example/README.md
Normal file
40
examples/translation-example/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# 机器翻译示例
|
||||
|
||||
|
||||
## 📁 项目结构
|
||||
|
||||
```
|
||||
|
||||
└── main
|
||||
├── java
|
||||
│ └── smartai
|
||||
│ └── examples
|
||||
│ └── nlp
|
||||
│ └── translation 机器翻译
|
||||
│ └── TranslationDemo.java
|
||||
└── resources
|
||||
└── logback.xml
|
||||
|
||||
|
||||
```
|
||||
---
|
||||
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
1. 克隆项目到本地:
|
||||
|
||||
2. 导入项目至 IntelliJ IDEA。
|
||||
|
||||
3. 根据需要修改模型路径(见各 demo 中注释)。
|
||||
|
||||
4. 运行对应的 JUnit 测试类方法即可体验各项功能。
|
||||
|
||||
---
|
||||
|
||||
## 📄 文档
|
||||
|
||||
有关完整使用说明,请查阅 SmartJavaAI 官方文档:
|
||||
[http://doc.smartjavaai.cn](http://doc.smartjavaai.cn)
|
||||
|
||||
---
|
||||
201
examples/translation-example/pom.xml
Normal file
201
examples/translation-example/pom.xml
Normal file
@@ -0,0 +1,201 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>cn.smartjavaai</groupId>
|
||||
<artifactId>examples</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<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.19</smartjavaai.version>
|
||||
<!--如果打包运行,需要替换成你的main-->
|
||||
<exec.mainClass>smartai.examples.nlp.translation.TranslationDemo</exec.mainClass>
|
||||
|
||||
<javacv.version>1.5.10</javacv.version>
|
||||
|
||||
<javacv.platform.macosx-arm64>macosx-arm64</javacv.platform.macosx-arm64>
|
||||
<javacv.platform.linux-x86_64>linux-x86_64</javacv.platform.linux-x86_64>
|
||||
<javacv.platform.linux-arm64>linux-arm64</javacv.platform.linux-arm64>
|
||||
<javacv.platform.windows-x86_64>windows-x86_64</javacv.platform.windows-x86_64>
|
||||
|
||||
|
||||
<djl.platform.windows-x86_64>win-x86_64</djl.platform.windows-x86_64>
|
||||
<djl.platform.linux-x86_64>linux-x86_64</djl.platform.linux-x86_64>
|
||||
<djl.platform.linux-aarch64>linux-aarch64</djl.platform.linux-aarch64>
|
||||
<djl.platform.osx-aarch64>osx-aarch64</djl.platform.osx-aarch64>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.smartjavaai</groupId>
|
||||
<artifactId>smartjavaai-bom</artifactId>
|
||||
<version>${smartjavaai.version}</version>
|
||||
<type>pom</type>
|
||||
<!-- 注意这里是import -->
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<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>
|
||||
<version>7.10.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<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>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.83</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
</dependency>
|
||||
|
||||
<!--翻译模块-->
|
||||
<dependency>
|
||||
<groupId>cn.smartjavaai</groupId>
|
||||
<artifactId>smartjavaai-translate</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-jni</artifactId>
|
||||
<version>2.5.1-0.32.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- windows平台 (保留对应平台的配置,可以减小包大小)-->
|
||||
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.windows-x86_64}</classifier>
|
||||
<version>2.5.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- linux x86 平台 (保留对应平台的配置,可以减小包大小)-->
|
||||
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.linux-x86_64}</classifier>
|
||||
<version>2.5.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- macOS M系列 平台 (保留对应平台的配置,可以减小包大小)-->
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.osx-aarch64}</classifier>
|
||||
<version>2.5.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- linux aarch64 平台 (保留对应平台的配置,可以减小包大小)-->
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals><goal>shade</goal></goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>${exec.mainClass}</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<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>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,100 @@
|
||||
package smartai.examples.nlp.translation;
|
||||
|
||||
import ai.djl.util.JsonUtils;
|
||||
import cn.smartjavaai.common.entity.R;
|
||||
import cn.smartjavaai.common.enums.DeviceEnum;
|
||||
import cn.smartjavaai.translation.config.TranslationModelConfig;
|
||||
import cn.smartjavaai.translation.entity.TranslateParam;
|
||||
import cn.smartjavaai.translation.enums.LanguageCode;
|
||||
import cn.smartjavaai.translation.enums.TranslationModeEnum;
|
||||
import cn.smartjavaai.translation.factory.TranslationModelFactory;
|
||||
import cn.smartjavaai.translation.model.TranslationModel;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 翻译Demo
|
||||
* 支持 Meta AI 开源的 NLLB-200 模型,实现 200 多种语言之间的高质量互译。
|
||||
* NLLB-200官网地址:https://github.com/facebookresearch/fairseq/tree/nllb
|
||||
* 模型下载地址:https://pan.baidu.com/s/1wf7btnb4cyBFv7DB7baHnw?pwd=1234 提取码: 1234
|
||||
* @author dwj
|
||||
*/
|
||||
@Slf4j
|
||||
public class TranslationDemo {
|
||||
|
||||
|
||||
/**
|
||||
* 翻译
|
||||
*/
|
||||
@Test
|
||||
public void translate() {
|
||||
try {
|
||||
TranslationModelConfig config = new TranslationModelConfig();
|
||||
//指定翻译模型:NLLB
|
||||
config.setModelEnum(TranslationModeEnum.NLLB_MODEL);
|
||||
//指定模型路径,需将模型路径修改为本地的模型路径
|
||||
config.setModelPath("/Users/xxx/Documents/develop/model/trans/traced_translation_cpu.pt");
|
||||
TranslationModel translationModel = TranslationModelFactory.getInstance().getModel(config);
|
||||
//翻译参数
|
||||
TranslateParam translateParam = new TranslateParam();
|
||||
//输入文字
|
||||
translateParam.setInput("你好,欢迎使用SmartJavaAI!");
|
||||
//源语言:中文
|
||||
translateParam.setSourceLanguage(LanguageCode.ZHO_HANS);
|
||||
//目标语言:英文
|
||||
translateParam.setTargetLanguage(LanguageCode.ENG_LATN);
|
||||
R<String> result = translationModel.translate(translateParam);
|
||||
if(result.isSuccess()){
|
||||
log.info("翻译结果:{}", result.getData());
|
||||
}else{
|
||||
log.error("翻译失败:{}", result.getMessage());
|
||||
}
|
||||
//目标语言:韩语
|
||||
translateParam.setTargetLanguage(LanguageCode.KOR_HANG);
|
||||
R<String> result2 = translationModel.translate(translateParam);
|
||||
if(result2.isSuccess()){
|
||||
log.info("翻译结果:{}", result2.getData());
|
||||
}else{
|
||||
log.error("翻译失败:{}", result2.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GPU 翻译
|
||||
*/
|
||||
@Test
|
||||
public void translateGpu() {
|
||||
try {
|
||||
TranslationModelConfig config = new TranslationModelConfig();
|
||||
//指定翻译模型:NLLB
|
||||
config.setModelEnum(TranslationModeEnum.NLLB_MODEL);
|
||||
//指定设备:GPU
|
||||
config.setDevice(DeviceEnum.GPU);
|
||||
//指定模型路径,需将模型路径修改为本地的 GPU 模型路径
|
||||
config.setModelPath("/Users/xxx/Documents/develop/model/trans/traced_translation_gpu.pt");
|
||||
//获取翻译模型
|
||||
TranslationModel translationModel = TranslationModelFactory.getInstance().getModel(config);
|
||||
//翻译参数
|
||||
TranslateParam translateParam = new TranslateParam();
|
||||
//输入文字
|
||||
translateParam.setInput("你好,欢迎使用SmartJavaAI!");
|
||||
//源语言:中文
|
||||
translateParam.setSourceLanguage(LanguageCode.ZHO_HANS);
|
||||
//目标语言:韩语
|
||||
translateParam.setTargetLanguage(LanguageCode.ENG_LATN);
|
||||
R<String> result = translationModel.translate(translateParam);
|
||||
if(result.isSuccess()){
|
||||
log.info("翻译结果:{}", result.getData());
|
||||
}else{
|
||||
log.error("翻译失败:{}", result.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: smartai.examples.face.SeetaFace6LinuxDemo
|
||||
|
||||
14
examples/translation-example/src/main/resources/logback.xml
Normal file
14
examples/translation-example/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 步骤2: 配置文件 (src/main/resources/logback.xml) -->
|
||||
<configuration scan="true" scanPeriod="30 seconds">
|
||||
<!-- 控制台日志输出 -->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{36}) - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user