diff --git a/code/crane/crane-api/.idea/encodings.xml b/code/crane/crane-api/.idea/encodings.xml index a820ac8d..3afa9e4b 100644 --- a/code/crane/crane-api/.idea/encodings.xml +++ b/code/crane/crane-api/.idea/encodings.xml @@ -15,6 +15,8 @@ + + diff --git a/code/crane/crane-api/crane-boot/pom.xml b/code/crane/crane-api/crane-boot/pom.xml index 5b42ad17..b9b15467 100644 --- a/code/crane/crane-api/crane-boot/pom.xml +++ b/code/crane/crane-api/crane-boot/pom.xml @@ -17,12 +17,14 @@ - + + org.springframework.boot + spring-boot-starter-web + com.crane - crane-common + crane-log - \ No newline at end of file diff --git a/code/crane/crane-api/crane-boot/src/main/java/com/crane/boot/CraneBootApplication.java b/code/crane/crane-api/crane-boot/src/main/java/com/crane/boot/CraneBootApplication.java index dd6c6ad0..858bfaa6 100644 --- a/code/crane/crane-api/crane-boot/src/main/java/com/crane/boot/CraneBootApplication.java +++ b/code/crane/crane-api/crane-boot/src/main/java/com/crane/boot/CraneBootApplication.java @@ -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); diff --git a/code/crane/crane-api/crane-boot/src/main/resources/application.yml b/code/crane/crane-api/crane-boot/src/main/resources/application.yml index 81d2279d..8f679e30 100644 --- a/code/crane/crane-api/crane-boot/src/main/resources/application.yml +++ b/code/crane/crane-api/crane-boot/src/main/resources/application.yml @@ -1,4 +1,6 @@ server: - port: 8080 + port: 8082 tomcat: uri-encoding: UTF-8 +logging: + module-name: 启动模块 diff --git a/code/crane/crane-api/crane-common/pom.xml b/code/crane/crane-api/crane-common/pom.xml index dce3d0dd..ba566410 100644 --- a/code/crane/crane-api/crane-common/pom.xml +++ b/code/crane/crane-api/crane-common/pom.xml @@ -13,8 +13,8 @@ - org.springframework.boot - spring-boot-starter-web + org.springframework + spring-web diff --git a/code/crane/crane-api/crane-common/src/main/resources/application.yml b/code/crane/crane-api/crane-common/src/main/resources/application.yml index e69de29b..1455741f 100644 --- a/code/crane/crane-api/crane-common/src/main/resources/application.yml +++ b/code/crane/crane-api/crane-common/src/main/resources/application.yml @@ -0,0 +1,2 @@ +logging: + module-name: common模块 diff --git a/code/crane/crane-api/crane-log/pom.xml b/code/crane/crane-api/crane-log/pom.xml index 468424dd..3d21f9ac 100644 --- a/code/crane/crane-api/crane-log/pom.xml +++ b/code/crane/crane-api/crane-log/pom.xml @@ -10,11 +10,6 @@ crane-log - - - 21 - 21 - UTF-8 - + 日志模块 \ No newline at end of file diff --git a/code/crane/crane-api/crane-test/pom.xml b/code/crane/crane-api/crane-test/pom.xml new file mode 100644 index 00000000..f7c29662 --- /dev/null +++ b/code/crane/crane-api/crane-test/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + com.crane + crane-api + 1.0.0 + + + crane-test + + + + com.crane + crane-common + + + + com.crane + crane-log + + + com.fasterxml.jackson.core + jackson-databind + + + + com.squareup.okhttp3 + okhttp + + + \ No newline at end of file diff --git a/code/crane/crane-api/crane-common/src/main/java/com/crane/common/DataController.java b/code/crane/crane-api/crane-test/src/main/java/com/crane/test/DataController.java similarity index 97% rename from code/crane/crane-api/crane-common/src/main/java/com/crane/common/DataController.java rename to code/crane/crane-api/crane-test/src/main/java/com/crane/test/DataController.java index 4a5255c4..fad11e90 100644 --- a/code/crane/crane-api/crane-common/src/main/java/com/crane/common/DataController.java +++ b/code/crane/crane-api/crane-test/src/main/java/com/crane/test/DataController.java @@ -1,4 +1,4 @@ -package com.crane.common; +package com.crane.test; import org.springframework.web.bind.annotation.*; diff --git a/code/crane/crane-api/crane-test/src/main/java/com/crane/test/Test.java b/code/crane/crane-api/crane-test/src/main/java/com/crane/test/Test.java new file mode 100644 index 00000000..c003bff7 --- /dev/null +++ b/code/crane/crane-api/crane-test/src/main/java/com/crane/test/Test.java @@ -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()); + } + } + } +} diff --git a/code/crane/crane-api/crane-test/src/main/resources/application.yml b/code/crane/crane-api/crane-test/src/main/resources/application.yml new file mode 100644 index 00000000..111e3bc4 --- /dev/null +++ b/code/crane/crane-api/crane-test/src/main/resources/application.yml @@ -0,0 +1,2 @@ +logging: + module-name: 测试模块 diff --git a/code/crane/crane-api/pom.xml b/code/crane/crane-api/pom.xml index 10c1a5b3..a9d1c2e4 100644 --- a/code/crane/crane-api/pom.xml +++ b/code/crane/crane-api/pom.xml @@ -16,6 +16,7 @@ crane-common crane-boot crane-log + crane-test @@ -80,6 +81,12 @@ crane-log ${crane.version} + + + com.crane + crane-test + ${crane.version} + diff --git a/notes/后端开发/python/assets/集装箱号识别/image-20250630093753262.png b/notes/后端开发/python/assets/集装箱号识别/image-20250630093753262.png new file mode 100644 index 00000000..06e029a0 Binary files /dev/null and b/notes/后端开发/python/assets/集装箱号识别/image-20250630093753262.png differ diff --git a/notes/后端开发/python/assets/集装箱号识别/image-20250630141231138.png b/notes/后端开发/python/assets/集装箱号识别/image-20250630141231138.png new file mode 100644 index 00000000..c830e1d5 Binary files /dev/null and b/notes/后端开发/python/assets/集装箱号识别/image-20250630141231138.png differ diff --git a/notes/后端开发/python/大模型-集装箱号识别.md b/notes/后端开发/python/大模型-集装箱号识别.md deleted file mode 100644 index 8c05ef35..00000000 --- a/notes/后端开发/python/大模型-集装箱号识别.md +++ /dev/null @@ -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/ -``` - - - -## 运行 - diff --git a/notes/后端开发/python/集装箱号识别.md b/notes/后端开发/python/集装箱号识别.md new file mode 100644 index 00000000..0f23e502 --- /dev/null +++ b/notes/后端开发/python/集装箱号识别.md @@ -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 +``` +