[Python] lstm-unicharset file is unable to be created during tesseract training

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to fine-tune an Optical Character Recognition (OCR) model on Tesseract's provided tesstrain repository for Japanese . I tried encoding the bash commands into Python in VSCode as I wanted to not just manually train the language model but automate the training process (Meaning, whenever I input the training data into a particular folder, it will train the model). However I am getting an issue here which I'm not sure how to solve:

    You are using make version: 4.4.1
    Makefile:438: *** mixed implicit and normal rules: deprecated syntax
    combine_tessdata -u C:/Users/Chan Jian Sen/Documents/TesseractFineTuningJpn5/tessdata/jpn.traineddata data/jpn/jpn1
    Failed to read C:/Users/Chan
    make: *** [Makefile:207: data/jpn/jpn1.lstm-unicharset] Error 1
    ❌ Training failed: Command '['make', 'unicharset', 'lists','proto-model', 'tesseract-langdata', 'training', 'MODEL_NAME=jpn1', 'START_MODEL=jpn', 'TESSDATA=C:/Users/Chan Jian Sen/Documents/TesseractFineT Training failed: Command '['make', 'unicharset', 'lists', 'proto-model', ATIONS=4000', 'LEARNING_RATE=0.001']' returned no
    uningJpn5/tessdata', 'GROUND_TRUTH_DIR=C:\\Users\\Chan Jian Sen\\Documents\\TesseractFineTuningJpn5\\tesstrain', 'MAX_ITERATIONS=4000', 'LEARNING_RATE=0.001']' returned non-zero exit status 2.


    Any explanations on what this could be about? It seems like the jpn1.lstm-unicharset is not able to be produced despite the fact that the code below should generate it:

    def run_tesseract_training(training_dir, model_name, start_model, max_iterations=4000): #previously start model is jpn
    """
    Run the full Tesseract tesstrain workflow including unicharset and langdata.
    """
    tessdata_path = r"C:\Users\Chan Jian Sen\Documents\TesseractFineTuningJpn5\tessdata"
    # Important: replace backslashes with forward slashes
    tessdata_path = tessdata_path.replace("\\", "/")
    command = [
    "make",
    "unicharset", "lists", "proto-model", "tesseract-langdata", "training",
    f"MODEL_NAME={model_name}",
    f"START_MODEL={start_model}",
    f"TESSDATA={tessdata_path}", # Adjust path depending on where your .traineddata are
    f"GROUND_TRUTH_DIR={training_dir}",
    f"MAX_ITERATIONS={max_iterations}",
    "LEARNING_RATE=0.001"
    ]

    print(" Running full Tesseract training pipeline...")
    try:
    subprocess.run(command, cwd=r"C:\Users\Chan Jian Sen\Documents\TesseractFineTuningJpn5\tesstrain", shell=True, check=True)
    print(f"✅ Training complete: {model_name}.traineddata generated.")
    except subprocess.CalledProcessError as e:
    print(f"❌ Training failed: {e}")

    Continue reading...

Compartilhe esta Página