ocr的SmartJavaAI离线
This commit is contained in:
parent
443b6e6f3c
commit
268d6bbdd6
34
pom.xml
34
pom.xml
@ -28,6 +28,8 @@
|
||||
<commons.version>2.6</commons.version>
|
||||
<swagger.ui.version>1.9.6</swagger.ui.version>
|
||||
<tomcat.version>9.0.30</tomcat.version>
|
||||
<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>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@ -92,6 +94,38 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--PyTorch离线平台依赖-->
|
||||
<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>
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-jni</artifactId>
|
||||
<version>2.5.1-0.32.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!--tensorflow离线平台依赖-->
|
||||
<dependency>
|
||||
<groupId>ai.djl.tensorflow</groupId>
|
||||
<artifactId>tensorflow-native-cpu</artifactId>
|
||||
<classifier>${djl.platform.linux-x86_64}</classifier>
|
||||
<scope>runtime</scope>
|
||||
<version>2.16.1</version>
|
||||
</dependency>
|
||||
<!--mxnet离线平台依赖-->
|
||||
<dependency>
|
||||
<groupId>ai.djl.mxnet</groupId>
|
||||
<artifactId>mxnet-native-mkl</artifactId>
|
||||
<classifier>${djl.platform.linux-x86_64}</classifier>
|
||||
<scope>runtime</scope>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java</artifactId>
|
||||
|
||||
@ -14,12 +14,17 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.xmgl.call.api.OcrManufacturer;
|
||||
import com.zhgd.xmgl.modules.ocr.entity.OcrConfig;
|
||||
import com.zhgd.xmgl.util.FileUtils;
|
||||
import com.zhgd.xmgl.util.PathUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Base64;
|
||||
|
||||
@Slf4j
|
||||
@ -62,8 +67,11 @@ public class SmartJavaAIOcrCall implements OcrManufacturer {
|
||||
recModelConfig.setRecModelEnum(CommonRecModelEnum.PP_OCR_V5_MOBILE_REC_MODEL);
|
||||
//指定识别模型位置,需要更改为自己的模型路径(下载地址请查看文档)
|
||||
// recModelConfig.setRecModelPath("/Users/xxx/Documents/develop/model/ocr/PP-OCRv5_mobile_rec_infer/PP-OCRv5_mobile_rec_infer.onnx");
|
||||
FileUtils.getExportTemplateFile("/models/ocr/dict.txt");
|
||||
recModelConfig.setRecModelPath(FileUtils.getExportTemplateFile("/models/ocr/PP-OCRv5_mobile_rec_infer.onnx").getAbsolutePath());
|
||||
String tmpdir = PathUtil.getBasePath();
|
||||
Files.copy(new ClassPathResource("/models/ocr/dict.txt").getInputStream(), Paths.get(tmpdir, "dict.txt"), StandardCopyOption.REPLACE_EXISTING);
|
||||
Path recModelPath = Paths.get(tmpdir, "PP-OCRv5_mobile_rec_infer.onnx");
|
||||
Files.copy(new ClassPathResource("/models/ocr/PP-OCRv5_mobile_rec_infer.onnx").getInputStream(), recModelPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
recModelConfig.setRecModelPath(recModelPath.toAbsolutePath().toString());
|
||||
recModelConfig.setDevice(device);
|
||||
recModelConfig.setTextDetModel(getDetectionModel());
|
||||
return OcrModelFactory.getInstance().getRecModel(recModelConfig);
|
||||
@ -80,7 +88,9 @@ public class SmartJavaAIOcrCall implements OcrManufacturer {
|
||||
config.setModelEnum(CommonDetModelEnum.PP_OCR_V5_MOBILE_DET_MODEL);
|
||||
//指定模型位置,需要更改为自己的模型路径(下载地址请查看文档)
|
||||
// config.setDetModelPath("/Users/xxx/Documents/develop/model/ocr/PP-OCRv5_mobile_det_infer/PP-OCRv5_mobile_det_infer.onnx");
|
||||
config.setDetModelPath(FileUtils.getExportTemplateFile("/models/ocr/PP-OCRv5_mobile_det_infer.onnx").getAbsolutePath());
|
||||
Path path = Paths.get(PathUtil.getBasePath(), "PP-OCRv5_mobile_det_infer.onnx");
|
||||
Files.copy(new ClassPathResource("/models/ocr/PP-OCRv5_mobile_det_infer.onnx").getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
|
||||
config.setDetModelPath(path.toAbsolutePath().toString());
|
||||
config.setDevice(device);
|
||||
return OcrModelFactory.getInstance().getDetModel(config);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user