"""Checks the training boundary: exact production inputs and valid CTC targets.""" import sys import unittest from pathlib import Path import numpy as np import torch from PIL import Image ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / 'docker_scripts/finetune_paddleocr_line_rec')) from train_ppocrv6_rec import RecDataset, checked_ctc_loss, make_collate class TrainingBoundaryTests(unittest.TestCase): def test_png_reconstructs_production_tensor(self): fixture = Path(__file__).parent / 'outputs/parity' image = Image.open(fixture / 'input.png').convert('RGB') item = dict(image=image, target=torch.tensor([1, 1]), text='AA', loss_weight=1., is_short=True, is_single_line=True, is_hard=False) batch = make_collate(None, prepared_inputs=True)([item]) expected = np.fromfile(fixture / 'tensor.f32', dtype='