This commit is contained in:
oneao committed 2025-06-30 17:29:28 +08:00
1 parent 9d7bf97823
commit 7c64e29ffb
16 files changed
+784 -35

No files matched your search

+2
View File
@@ -15,6 +15,8 @@
<file url="file://$PROJECT_DIR$/crane-doc/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-log/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-log/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-test/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-test/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-web/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-web/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+5 -3
View File
@@ -17,12 +17,14 @@
</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-common</artifactId>
<artifactId>crane-log</artifactId>
</dependency>
</dependencies>
</project>
@@ -3,7 +3,7 @@ package com.crane.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.crane"})
public class CraneBootApplication {
public static void main(String[] args) {
SpringApplication.run(CraneBootApplication.class, args);
@@ -1,4 +1,6 @@
server:
port: 8080
port: 8082
tomcat:
uri-encoding: UTF-8
logging:
module-name: 启动模块
+2 -2
View File
@@ -13,8 +13,8 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
@@ -0,0 +1,2 @@
logging:
module-name: common模块
+1 -6
View File
@@ -10,11 +10,6 @@
</parent>
<artifactId>crane-log</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>日志模块</description>
</project>
+34
View File
@@ -0,0 +1,34 @@
<?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>
<parent>
<groupId>com.crane</groupId>
<artifactId>crane-api</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>crane-test</artifactId>
<dependencies>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-common</artifactId>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-log</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
</dependencies>
</project>
@@ -1,4 +1,4 @@
package com.crane.common;
package com.crane.test;
import org.springframework.web.bind.annotation.*;
@@ -0,0 +1,61 @@
package com.crane.test;
import okhttp3.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Base64;
public class Test{
public static void main(String[] args) throws IOException {
String API_URL = "http://localhost:8080/ocr";
String imagePath = "./demo.jpg";
File file = new File(imagePath);
byte[] fileContent = java.nio.file.Files.readAllBytes(file.toPath());
String base64Image = Base64.getEncoder().encodeToString(fileContent);
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode payload = objectMapper.createObjectNode();
payload.put("file", base64Image);
payload.put("fileType", 1);
OkHttpClient client = new OkHttpClient();
MediaType JSON = MediaType.get("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, payload.toString());
Request request = new Request.Builder()
.url(API_URL)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String responseBody = response.body().string();
JsonNode root = objectMapper.readTree(responseBody);
JsonNode result = root.get("result");
JsonNode ocrResults = result.get("ocrResults");
for (int i = 0; i < ocrResults.size(); i++) {
JsonNode item = ocrResults.get(i);
JsonNode prunedResult = item.get("prunedResult");
System.out.println("Pruned Result [" + i + "]: " + prunedResult.toString());
String ocrImageBase64 = item.get("ocrImage").asText();
byte[] ocrImageBytes = Base64.getDecoder().decode(ocrImageBase64);
String ocrImgPath = "ocr_result_" + i + ".jpg";
try (FileOutputStream fos = new FileOutputStream(ocrImgPath)) {
fos.write(ocrImageBytes);
System.out.println("Saved OCR image to: " + ocrImgPath);
}
}
} else {
System.err.println("Request failed with HTTP code: " + response.code());
}
}
}
}
@@ -0,0 +1,2 @@
logging:
module-name: 测试模块
+7
View File
@@ -16,6 +16,7 @@
<module>crane-common</module>
<module>crane-boot</module>
<module>crane-log</module>
<module>crane-test</module>
</modules>
<!-- 版本信息 -->
@@ -80,6 +81,12 @@
<artifactId>crane-log</artifactId>
<version>${crane.version}</version>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-test</artifactId>
<version>${crane.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

@@ -1,21 +0,0 @@
## 环境
- python:3.11.13
- paddlepaddle-gpu:3.0.0
- paddle-ocr:3.0.1
- cuda:11.8
## 依赖
paddlepaddle-gpu
```bash
pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
```
## 运行
@@ -0,0 +1,663 @@
# 识别结果
参数基本采用默认参数,都训练 **10轮** 。
## PP-OCRv5_server (极好)
识别效果:**极好** ,基本都是别出来了,并且正确。
![image-20250630141231138](./assets/%E9%9B%86%E8%A3%85%E7%AE%B1%E5%8F%B7%E8%AF%86%E5%88%AB/image-20250630141231138.png)
### PP-OCRv5_server_det.yml
```yaml
Global:
model_name: PP-OCRv5_server_det # To use static model for inference.
debug: false
use_gpu: true
epoch_num: &epoch_num 10
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output-v5server/PP-OCRv5_server_det
save_epoch_step: 200
eval_batch_step:
- 0
- 200
cal_metric_during_train: false
checkpoints:
pretrained_model: ./pretrain_models/PP-OCRv5_server_det_pretrained.pdparams
save_inference_dir: null
use_visualdl: false
infer_img: doc/imgs_en/img_10.jpg
save_res_path: ./checkpoints/det_db/predicts_db.txt
distributed: false
Architecture:
model_type: det
algorithm: DB
Transform: null
Backbone:
name: PPHGNetV2_B4
det: True
Neck:
name: LKPAN
out_channels: 256
intracl: true
Head:
name: PFHeadLocal
k: 50
mode: "large"
Loss:
name: DBLoss
balance_loss: true
main_loss_type: DiceLoss
alpha: 5
beta: 10
ohem_ratio: 3
Optimizer:
name: Adam
beta1: 0.9
beta2: 0.999
lr:
name: Cosine
learning_rate: 0.001 #(8*8c)
warmup_epoch: 2
regularizer:
name: L2
factor: 1e-6
PostProcess:
name: DBPostProcess
thresh: 0.3
box_thresh: 0.6
max_candidates: 1000
unclip_ratio: 1.5
Metric:
name: DetMetric
main_indicator: hmean
Train:
dataset:
name: SimpleDataSet
data_dir: ./data/input0/images #图片文件夹路径
label_file_list:
- ./det_train_label.txt #标签路径
ratio_list: [1.0]
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- DetLabelEncode: null
- CopyPaste: null
- IaaAugment:
augmenter_args:
- type: Fliplr
args:
p: 0.5
- type: Affine
args:
rotate:
- -10
- 10
- type: Resize
args:
size:
- 0.5
- 3
- EastRandomCropData:
size:
- 640
- 640
max_tries: 50
keep_ratio: true
- MakeBorderMap:
shrink_ratio: 0.4
thresh_min: 0.3
thresh_max: 0.7
total_epoch: *epoch_num
- MakeShrinkMap:
shrink_ratio: 0.4
min_text_size: 8
total_epoch: *epoch_num
- NormalizeImage:
scale: 1./255.
mean:
- 0.485
- 0.456
- 0.406
std:
- 0.229
- 0.224
- 0.225
order: hwc
- ToCHWImage: null
- KeepKeys:
keep_keys:
- image
- threshold_map
- threshold_mask
- shrink_map
- shrink_mask
loader:
shuffle: true
drop_last: false
batch_size_per_card: 10
num_workers: 1
Eval:
dataset:
name: SimpleDataSet
data_dir: ./data/input0/images
label_file_list:
- ./det_eval_label.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- DetLabelEncode: null
- DetResizeForTest:
- NormalizeImage:
scale: 1./255.
mean:
- 0.485
- 0.456
- 0.406
std:
- 0.229
- 0.224
- 0.225
order: hwc
- ToCHWImage: null
- KeepKeys:
keep_keys:
- image
- shape
- polys
- ignore_tags
loader:
shuffle: false
drop_last: false
batch_size_per_card: 1
num_workers: 1
profiler_options: null
```
### PP-OCRv5_server_rec.yml
```yaml
Global:
model_name: PP-OCRv5_server_rec # To use static model for inference.
debug: false
use_gpu: true
epoch_num: 10
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output-v5server/PP-OCRv5_server_rec
save_epoch_step: 200
eval_batch_step: [0, 200]
cal_metric_during_train: true
calc_epoch_interval: 1
pretrained_model: ./pretrain_models/PP-OCRv5_server_rec_pretrained.pdparams
checkpoints:
save_inference_dir:
use_visualdl: false
infer_img: doc/imgs_words/ch/word_1.jpg
character_dict_path: ./ppocr/utils/dict/ppocrv5_dict.txt
max_text_length: &max_text_length 25
infer_mode: false
use_space_char: true
distributed: true
save_res_path: ./output-v5server/rec/predicts_ppocrv5.txt
d2s_train_image_shape: [3, 48, 320]
Optimizer:
name: Adam
beta1: 0.9
beta2: 0.999
lr:
name: Cosine
learning_rate: 0.0005
warmup_epoch: 1
regularizer:
name: L2
factor: 3.0e-05
Architecture:
model_type: rec
algorithm: SVTR_HGNet
Transform:
Backbone:
name: PPHGNetV2_B4
text_rec: True
Head:
name: MultiHead
head_list:
- CTCHead:
Neck:
name: svtr
dims: 120
depth: 2
hidden_dims: 120
kernel_size: [1, 3]
use_guide: True
Head:
fc_decay: 0.00001
- NRTRHead:
nrtr_dim: 384
max_text_length: *max_text_length
Loss:
name: MultiLoss
loss_config_list:
- CTCLoss:
- NRTRLoss:
PostProcess:
name: CTCLabelDecode
Metric:
name: RecMetric
main_indicator: acc
Train:
dataset:
name: MultiScaleDataSet
ds_width: false
data_dir: ./RecTrainData/
ext_op_transform_idx: 1
label_file_list:
- ./rec_train_label.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- RecAug:
- MultiLabelEncode:
gtc_encode: NRTRLabelEncode
- KeepKeys:
keep_keys:
- image
- label_ctc
- label_gtc
- length
- valid_ratio
sampler:
name: MultiScaleSampler
scales: [[320, 32], [320, 48], [320, 64]]
first_bs: &bs 12
fix_bs: false
divided_factor: [8, 16] # w, h
is_training: True
loader:
shuffle: true
batch_size_per_card: 10
drop_last: true
num_workers: 1
Eval:
dataset:
name: SimpleDataSet
data_dir: ./RecEvalData/
label_file_list:
- ./rec_eval_label.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- MultiLabelEncode:
gtc_encode: NRTRLabelEncode
- RecResizeImg:
image_shape: [3, 48, 320]
- KeepKeys:
keep_keys:
- image
- label_ctc
- label_gtc
- length
- valid_ratio
loader:
shuffle: false
drop_last: false
batch_size_per_card: 1
num_workers: 1
```
## PP-OCRv5_mobile
### PP-OCRv5_mobile_det.yml
```yaml
Global:
model_name: PP-OCRv5_mobile_det # To use static model for inference.
debug: false
use_gpu: true
epoch_num: &epoch_num 100
log_smooth_window: 20
print_batch_step: 100
save_model_dir: ./output-v5mobile/PP-OCRv5_mobile_det
save_epoch_step: 200
eval_batch_step:
- 0
- 200
cal_metric_during_train: false
checkpoints:
pretrained_model: https://paddleocr.bj.bcebos.com/pretrained/PPLCNetV3_x0_75_ocr_det.pdparams
save_inference_dir: null
use_visualdl: false
infer_img: doc/imgs_en/img_10.jpg
save_res_path: ./checkpoints/det_db/predicts_db.txt
d2s_train_image_shape: [3, 640, 640]
distributed: true
Architecture:
model_type: det
algorithm: DB
Transform: null
Backbone:
name: PPLCNetV3
scale: 0.75
det: True
Neck:
name: RSEFPN
out_channels: 96
shortcut: True
Head:
name: DBHead
k: 50
fix_nan: True
Loss:
name: DBLoss
balance_loss: true
main_loss_type: DiceLoss
alpha: 5
beta: 10
ohem_ratio: 3
Optimizer:
name: Adam
beta1: 0.9
beta2: 0.999
lr:
name: Cosine
learning_rate: 0.001 #(8*8c)
warmup_epoch: 2
regularizer:
name: L2
factor: 5.0e-05
PostProcess:
name: DBPostProcess
thresh: 0.3
box_thresh: 0.6
max_candidates: 1000
unclip_ratio: 1.5
Metric:
name: DetMetric
main_indicator: hmean
Train:
dataset:
name: SimpleDataSet
data_dir: ./data/input0/images #图片文件夹路径
label_file_list:
- ./det_train_label.txt #标签路径
ratio_list: [1.0]
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- DetLabelEncode: null
- CopyPaste: null
- IaaAugment:
augmenter_args:
- type: Fliplr
args:
p: 0.5
- type: Affine
args:
rotate:
- -10
- 10
- type: Resize
args:
size:
- 0.5
- 3
- EastRandomCropData:
size:
- 640
- 640
max_tries: 50
keep_ratio: true
- MakeBorderMap:
shrink_ratio: 0.4
thresh_min: 0.3
thresh_max: 0.7
total_epoch: *epoch_num
- MakeShrinkMap:
shrink_ratio: 0.4
min_text_size: 8
total_epoch: *epoch_num
- NormalizeImage:
scale: 1./255.
mean:
- 0.485
- 0.456
- 0.406
std:
- 0.229
- 0.224
- 0.225
order: hwc
- ToCHWImage: null
- KeepKeys:
keep_keys:
- image
- threshold_map
- threshold_mask
- shrink_map
- shrink_mask
loader:
shuffle: true
drop_last: false
batch_size_per_card: 14
num_workers: 1
Eval:
dataset:
name: SimpleDataSet
data_dir: ./data/input0/images
label_file_list:
- ./det_eval_label.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- DetLabelEncode: null
- DetResizeForTest:
- NormalizeImage:
scale: 1./255.
mean:
- 0.485
- 0.456
- 0.406
std:
- 0.229
- 0.224
- 0.225
order: hwc
- ToCHWImage: null
- KeepKeys:
keep_keys:
- image
- shape
- polys
- ignore_tags
loader:
shuffle: false
drop_last: false
batch_size_per_card: 1
num_workers: 1
profiler_options: null
```
### PP-OCRv5_mobile_rec.yml
```yaml
Global:
model_name: PP-OCRv5_mobile_rec # To use static model for inference.
debug: false
use_gpu: true
epoch_num: 75
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output/PP-OCRv5_mobile_rec
save_epoch_step: 10
eval_batch_step: [0, 2000]
cal_metric_during_train: true
pretrained_model: https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv5_mobile_rec_pretrained.pdparams
checkpoints:
save_inference_dir:
use_visualdl: false
infer_img: doc/imgs_words/ch/word_1.jpg
character_dict_path: ./ppocr/utils/dict/ppocrv5_dict.txt
max_text_length: &max_text_length 25
infer_mode: false
use_space_char: true
distributed: true
save_res_path: ./output/rec/predicts_ppocrv5.txt
d2s_train_image_shape: [3, 48, 320]
Optimizer:
name: Adam
beta1: 0.9
beta2: 0.999
lr:
name: Cosine
learning_rate: 0.0005
warmup_epoch: 5
regularizer:
name: L2
factor: 3.0e-05
Architecture:
model_type: rec
algorithm: SVTR_LCNet
Transform:
Backbone:
name: PPLCNetV3
scale: 0.95
Head:
name: MultiHead
head_list:
- CTCHead:
Neck:
name: svtr
dims: 120
depth: 2
hidden_dims: 120
kernel_size: [1, 3]
use_guide: True
Head:
fc_decay: 0.00001
- NRTRHead:
nrtr_dim: 384
max_text_length: *max_text_length
Loss:
name: MultiLoss
loss_config_list:
- CTCLoss:
- NRTRLoss:
PostProcess:
name: CTCLabelDecode
Metric:
name: RecMetric
main_indicator: acc
Train:
dataset:
name: MultiScaleDataSet
ds_width: false
data_dir: ./RecTrainData/
ext_op_transform_idx: 1
label_file_list:
- ./rec_train_label.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- RecConAug:
prob: 0.5
ext_data_num: 2
image_shape: [48, 320, 3]
max_text_length: *max_text_length
- RecAug:
- MultiLabelEncode:
gtc_encode: NRTRLabelEncode
- KeepKeys:
keep_keys:
- image
- label_ctc
- label_gtc
- length
- valid_ratio
sampler:
name: MultiScaleSampler
scales: [[320, 32], [320, 48], [320, 64]]
first_bs: &bs 128
fix_bs: false
divided_factor: [8, 16] # w, h
is_training: True
loader:
shuffle: true
batch_size_per_card: 14
drop_last: true
num_workers: 1
Eval:
dataset:
name: SimpleDataSet
data_dir: ./RecEvalData/
label_file_list:
- ./rec_eval_label.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- MultiLabelEncode:
gtc_encode: NRTRLabelEncode
- RecResizeImg:
image_shape: [3, 48, 320]
- KeepKeys:
keep_keys:
- image
- label_ctc
- label_gtc
- length
- valid_ratio
loader:
shuffle: false
drop_last: false
batch_size_per_card: 14
num_workers: 1
```