Compare commits
3 Commits
a772fdad77
...
149dd86132
| Author | SHA1 | Date | |
|---|---|---|---|
| 149dd86132 | |||
| 96ee97f802 | |||
| 410ac16efd |
@@ -1,8 +1,42 @@
|
|||||||
Global:
|
Global:
|
||||||
|
model_name: PP-OCRv5_server_rec # To use static model for inference.
|
||||||
|
debug: false
|
||||||
use_gpu: false
|
use_gpu: false
|
||||||
character_dict_path: train_data/dict.txt
|
device: cpu
|
||||||
save_model_dir: ./output/
|
epoch_num: 75
|
||||||
pretrained_model: pretrained_models/PP-OCRv5_server_rec_pretrained.pdparams
|
log_smooth_window: 20
|
||||||
|
print_batch_step: 10
|
||||||
|
save_model_dir: ./output/PP-OCRv5_server_rec
|
||||||
|
save_epoch_step: 1
|
||||||
|
eval_batch_step: [0, 2000]
|
||||||
|
cal_metric_during_train: true
|
||||||
|
calc_epoch_interval: 1
|
||||||
|
pretrained_model:
|
||||||
|
checkpoints:
|
||||||
|
save_inference_dir:
|
||||||
|
use_visualdl: false
|
||||||
|
infer_img: ./train_data/images/1C4HJXEN3MW645094.jpg
|
||||||
|
character_dict_path: ./train_data/dict.txt
|
||||||
|
max_text_length: &max_text_length 19
|
||||||
|
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: 1
|
||||||
|
regularizer:
|
||||||
|
name: L2
|
||||||
|
factor: 3.0e-05
|
||||||
|
|
||||||
|
|
||||||
Architecture:
|
Architecture:
|
||||||
model_type: rec
|
model_type: rec
|
||||||
@@ -26,7 +60,13 @@ Architecture:
|
|||||||
fc_decay: 0.00001
|
fc_decay: 0.00001
|
||||||
- NRTRHead:
|
- NRTRHead:
|
||||||
nrtr_dim: 384
|
nrtr_dim: 384
|
||||||
max_text_length: 17
|
max_text_length: *max_text_length
|
||||||
|
|
||||||
|
Loss:
|
||||||
|
name: MultiLoss
|
||||||
|
loss_config_list:
|
||||||
|
- CTCLoss:
|
||||||
|
- NRTRLoss:
|
||||||
|
|
||||||
PostProcess:
|
PostProcess:
|
||||||
name: CTCLabelDecode
|
name: CTCLabelDecode
|
||||||
@@ -37,27 +77,50 @@ Metric:
|
|||||||
|
|
||||||
Train:
|
Train:
|
||||||
dataset:
|
dataset:
|
||||||
name: SimpleDataSet
|
name: MultiScaleDataSet
|
||||||
data_dir: train_data/
|
ds_width: false
|
||||||
|
data_dir: ./train_data/images
|
||||||
|
ext_op_transform_idx: 1
|
||||||
label_file_list:
|
label_file_list:
|
||||||
- train_data/train.txt
|
- ./train_data/train.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 128
|
||||||
|
fix_bs: false
|
||||||
|
divided_factor: [8, 16] # w, h
|
||||||
|
is_training: True
|
||||||
loader:
|
loader:
|
||||||
batch_size_per_card: 16 # Уменьшите для экономии памяти
|
shuffle: true
|
||||||
num_workers: 2
|
batch_size_per_card: *bs
|
||||||
|
drop_last: true
|
||||||
|
num_workers: 16
|
||||||
Eval:
|
Eval:
|
||||||
dataset:
|
dataset:
|
||||||
name: SimpleDataSet
|
name: SimpleDataSet
|
||||||
data_dir: train_data/
|
data_dir: ./train_data/images
|
||||||
label_file_list:
|
label_file_list:
|
||||||
- train_data/val.txt
|
- ./train_data/val.txt
|
||||||
transforms:
|
transforms:
|
||||||
- DecodeImage:
|
- DecodeImage:
|
||||||
img_mode: BGR
|
img_mode: BGR
|
||||||
channel_first: false
|
channel_first: false
|
||||||
- MultiLabelEncode:
|
- MultiLabelEncode:
|
||||||
gtc_encode: NRTRLabelEncode
|
gtc_encode: NRTRLabelEncode
|
||||||
max_text_length: 17
|
|
||||||
- RecResizeImg:
|
- RecResizeImg:
|
||||||
image_shape: [3, 48, 320]
|
image_shape: [3, 48, 320]
|
||||||
- KeepKeys:
|
- KeepKeys:
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import os
|
|
||||||
import cv2
|
import cv2
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
def rename_files(directory_path: str):
|
def rename_files(directory_path: str):
|
||||||
extensions = set()
|
extensions = set()
|
||||||
@@ -37,8 +39,51 @@ def check_symbols(dir_path: str):
|
|||||||
if any([char not in dict_chars for char in label]):
|
if any([char not in dict_chars for char in label]):
|
||||||
print(filename)
|
print(filename)
|
||||||
|
|
||||||
|
def max_height(dir_path: str):
|
||||||
|
max_height = 0
|
||||||
|
max_filename = ''
|
||||||
|
for filename in os.listdir(dir_path):
|
||||||
|
im = Image.open(os.path.join(dir_path, filename))
|
||||||
|
if im.height > max_height:
|
||||||
|
max_height = im.height
|
||||||
|
max_filename = filename
|
||||||
|
|
||||||
|
print(max_filename, max_height)
|
||||||
|
|
||||||
|
def resize_to_height(dir_path: str, target_height=48):
|
||||||
|
for filename in os.listdir(dir_path):
|
||||||
|
with Image.open(os.path.join(dir_path, filename)) as img:
|
||||||
|
width_percent = target_height / float(img.height)
|
||||||
|
new_width = int(float(img.width) * width_percent)
|
||||||
|
resized_img = img.resize((new_width, target_height), Image.LANZOS)
|
||||||
|
resized_img.save(os.path.join(dir_path, filename))
|
||||||
|
|
||||||
|
def split_dataset(dir_path: str):
|
||||||
|
images_dir = os.path.join(dir_path, "images")
|
||||||
|
filenames = os.listdir(images_dir)
|
||||||
|
dataset_length = len(filenames)
|
||||||
|
random.shuffle(filenames)
|
||||||
|
train_ratio = 0.8
|
||||||
|
val_ratio = 0.2
|
||||||
|
train_files_len = round(dataset_length * train_ratio)
|
||||||
|
val_files_len = round(dataset_length * val_ratio)
|
||||||
|
train_files = filenames[:train_files_len]
|
||||||
|
val_files = filenames[train_files_len:train_files_len+val_files_len]
|
||||||
|
train_file_path = os.path.join(dir_path, "train.txt")
|
||||||
|
val_file_path = os.path.join(dir_path, "val.txt")
|
||||||
|
with open(train_file_path, "w") as train_file:
|
||||||
|
for filename in train_files:
|
||||||
|
label, _ = filename.split(".")
|
||||||
|
train_file.write(f"{filename}\t{label}\n")
|
||||||
|
|
||||||
|
with open(val_file_path, "w") as val_file:
|
||||||
|
for filename in val_files:
|
||||||
|
label, _ = filename.split(".")
|
||||||
|
val_file.write(f"{filename}\t{label}\n")
|
||||||
|
|
||||||
# rename_files("train_data/images/")
|
# rename_files("train_data/images/")
|
||||||
# check_images("train_data/images/")
|
# check_images("train_data/images/")
|
||||||
# check_labels("train_data/images/")
|
# check_labels("train_data/images/")
|
||||||
check_symbols("train_data/")
|
# check_symbols("train_data/")
|
||||||
|
# max_height("train_data/images")
|
||||||
|
split_dataset("train_data/")
|
||||||
|
|||||||
Reference in New Issue
Block a user