From 4d97e3bf7ff3de7e6aa8a31ff8cdaf61a583ce33 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Wed, 15 Jul 2026 12:46:33 +0200 Subject: [PATCH] training: fix typos found by ruff --- src/eynollah/training/utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/eynollah/training/utils.py b/src/eynollah/training/utils.py index e84ac66..d04a17b 100644 --- a/src/eynollah/training/utils.py +++ b/src/eynollah/training/utils.py @@ -1127,13 +1127,21 @@ def preprocess_img_ocr( if task == 'cnn-rnn-ocr': assert char_to_num, 'task is cnn-rnn-ocr, so preprocess_imgs_ocr should be passed "char_to_num"' lab = char_to_num(tf.strings.unicode_split(lab, input_encoding="UTF-8")) - yield_encoder = lambda x: x + def yield_encoder(x): + return x elif task == 'transformer-ocr': + import torch assert processor, 'task is transformer-ocr, so preprocess_imgs_ocr should be passed "processor"' # TODO make max_length configurable again, if deemed sensible - lab = [l if l != self.processor.tokenizer.pad_token_id else -100 - for l in processor.tokenizer(lab, padding="max_length", max_length=128).input_ids] - yield_encoder = lambda img_, lab_: {"pixel_values": processor(Image.fromarray(img_), return_tensors="pt").pixel_values.squeeze(), "labels": torch.tensor(lab_)} + lab = [tok if tok != processor.tokenizer.pad_token_id else -100 + for tok in processor.tokenizer(lab, + padding="max_length", + max_length=128 + ).input_ids] + def yield_encoder(img_, lab_): + return {"pixel_values": processor(Image.fromarray(img_), + return_tensors="pt").pixel_values.squeeze(), + "labels": torch.tensor(lab_)} yield yield_encoder(scale_image(img), lab) #to_yield = {"image": ret_x, "label": ret_y}