On Windows the last batch of every epoch and of every evaluation is skipped (`len(dataloader) - 1` in tools/program.py, a workaround from 2021)
🔎 Search before asking
- [x] I have searched the PaddleOCR Docs and found no similar bug report.
- [x] I have searched the PaddleOCR Issues and found no similar bug report.
- [x] I have searched the PaddleOCR Discussions and found no similar bug report.
🐛 Bug (问题描述)
On Windows, tools/program.py stops its loops one batch early. The limit is in four places (train, twice; eval; get_center):
max_iter = (
len(train_dataloader) - 1
if platform.system() == "Windows"
else len(train_dataloader)
)
...
for idx, batch in enumerate(train_dataloader):
...
if idx >= max_iter:
break
So on Windows the last batch of every epoch is never trained on, and the last batch of every evaluation is never scored (with a fixed evaluation order it is always the same samples). A dataset that fits in one batch does not train or evaluate at all. Nothing is logged about it, and the same command gives different results on Windows and on Linux.
The limit comes from April 2021: #2636 reported that training on Windows 10 broke off at "eval model", #2654 ("fix eval laoder on win") added it for evaluation and d5651dfa ("fix win train loader") for training. It looks like a workaround for a crash at the end of the data loader with the Paddle version of that time.
With PaddlePaddle 3.3.1 on Windows 11 I do not see that crash any more. A toy set of 40 word images, batch size 4 (10 iterations), configs/rec/rec_icdar15_train.yml, 1 epoch, through tools/train.py and tools/eval.py:
| code | device | loader workers | runs | training steps logged | evaluation batches scored | exit code |
|---|---|---|---|---|---|---|
main (dab3fe3) |
GPU | 0 and 2 | 2 | 9 of 10 | 9 of 10 | 0 |
main (dab3fe3) |
CPU | 0 and 2 | 2 | 9 of 10 | 9 of 10 | 0 |
| limit removed | GPU | 0 and 2 | 6 | 10 of 10 | 10 of 10 | 0 |
| limit removed | CPU | 0 and 2 | 6 | 10 of 10 | 10 of 10 | 0 |
On main the log says train dataloader has 10 iters, the last step printed is global_step: 9, and the evaluation bar ends at eval model:: 90%|######### | 9/10. Without the limit the log reaches global_step: 10 and the bar 100%|##########| 10/10; each setting was run three times, with no crash or hang.
Expected: every batch is used on Windows, as on Linux.
I can open a pull request that removes the limit. I could only test PaddlePaddle 3.3.1 on Windows 11 with a recognition config; if the limit is still needed for some setup, a comment in the code saying so would already help.
🏃♂️ Environment (运行环境)
OS Windows 11
Environment terminal
Python 3.12.10
PaddleOCR main (dab3fe3, 2026-09-16)
PaddlePaddle 3.3.1 (GPU build)
Install git
RAM 15.2 GB
CPU AMD Ryzen 9 6900HS
GPU NVIDIA RTX 3070 Ti Laptop (8 GB)
🌰 Minimal Reproducible Example (最小可复现问题的Demo)
make_toy.py (a toy set: 40 small word images for training, 40 for evaluation):
import os
from PIL import Image, ImageDraw
for split in ("train", "eval"):
os.makedirs(f"toy/{split}", exist_ok=True)
lines = []
for i in range(40):
word = f"word{i:02d}"
im = Image.new("RGB", (100, 32), "white")
ImageDraw.Draw(im).text((4, 8), word, fill="black")
im.save(f"toy/{split}/{i:03d}.png")
lines.append(f"{split}/{i:03d}.png\t{word}")
with open(f"toy/{split}.txt", "w") as f:
f.write("\n".join(lines) + "\n")
# on Windows, from the repository root
python make_toy.py
# 40 images, batch size 4 -> 10 iterations
python tools/train.py -c configs/rec/rec_icdar15_train.yml -o Global.epoch_num=1 Global.print_batch_step=1 Global.save_epoch_step=1 Global.eval_batch_step=[0,100000] Global.cal_metric_during_train=False Train.dataset.data_dir=./toy/ Train.dataset.label_file_list=['./toy/train.txt'] Train.loader.batch_size_per_card=4 Train.loader.shuffle=False Train.loader.num_workers=0 Eval.dataset.data_dir=./toy/ Eval.dataset.label_file_list=['./toy/eval.txt'] Eval.loader.batch_size_per_card=4 Eval.loader.num_workers=0
# log: "train dataloader has 10 iters", but the last step is "global_step: 9"
python tools/eval.py -c configs/rec/rec_icdar15_train.yml -o Global.checkpoints=./output/rec/ic15/latest Eval.dataset.data_dir=./toy/ Eval.dataset.label_file_list=['./toy/eval.txt'] Eval.loader.batch_size_per_card=4 Eval.loader.num_workers=0
# the bar ends at "eval model:: 90%|######### | 9/10"