Files
CaptchBreaker/training/train_math.py
2026-03-10 18:47:29 +08:00

41 lines
952 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
训练算式识别模型 (LiteCRNN - math 模式)
用法: python -m training.train_math
"""
from config import (
MATH_CHARS,
IMAGE_SIZE,
SYNTHETIC_MATH_DIR,
REAL_MATH_DIR,
)
from generators.math_gen import MathCaptchaGenerator
from models.lite_crnn import LiteCRNN
from training.train_utils import train_ctc_model
def main():
img_h, img_w = IMAGE_SIZE["math"]
model = LiteCRNN(chars=MATH_CHARS, img_h=img_h, img_w=img_w)
print("=" * 60)
print("训练算式识别模型 (LiteCRNN - math)")
print(f" 字符集: {MATH_CHARS} ({len(MATH_CHARS)} 字符)")
print(f" 输入尺寸: {img_h}×{img_w}")
print("=" * 60)
train_ctc_model(
model_name="math",
model=model,
chars=MATH_CHARS,
synthetic_dir=SYNTHETIC_MATH_DIR,
real_dir=REAL_MATH_DIR,
generator_cls=MathCaptchaGenerator,
config_key="math",
)
if __name__ == "__main__":
main()