Restore the rectangular imgsz a checkpoint was trained at (#899) - #901
Merged
Merged
Conversation
A model trained with imgsz=(h, w) dual-writes imgsz_h/imgsz_w, but the base loader ignored them, so predict/val/export went back to the family's square default. Restore the pair on load, keep the live model in sync after train(), and harden the paths that assumed a square size: default export falls back to max(h, w) where rectangular export is not supported, tiling uses the long side, YOLOX recomputes the val ratio per axis, TTA undoes the letterbox at the preprocessed canvas, and the quantized-checkpoint finalize and the inference profiler accept pairs.
EHxuban11
added a commit
that referenced
this pull request
Sep 26, 2026
Restore the rectangular imgsz a checkpoint was trained at (#899)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What: reload a rectangular fine-tune at the
imgsz=(h, w)it was trained at.Why: #899. Checkpoints store
imgsz_h/imgsz_w, but the base loader ignored them, so predict/val/export fell back to the family's square default and padded frames again (43.75% padding for a 1920x1080 frame at 640)._load_weightsrestores the pair (square pairs collapse to an int; a half pair raises). Checkpoints without the pair load exactly as before.train(): adopts a rectangular run's size, drops a restored rectangle after a later square run. Natively rectangular families (HRNet, PP-LiteSeg, U-Net) are skipped.export()where the family/format pair has no rectangular export (YOLOX, YOLOv7, RTMDet, PicoDet; YOLO9 to ExecuTorch/Paddle/MNN) falls back to amax(h, w)square with a warning instead of raising. Explicit rectangularimgszstill raises as before. CLIexport --jsonreports the exported canvas.predict(tiling=True)tiles and infers at the long side instead of raising.val(imgsz=(h, w))TypeError(already on dev); TTA undid the letterbox at the family default instead of the requestedimgsz(already on dev); YOLO9-E2E postprocess defaulted to 640; quantizedexport(format="pt")crashed on / dropped the pair; PythonInferenceProfilercrashed on it; val preprocessor andcapture_graphassumed square.Check:
_restore_checkpoint_input_size/_adopt_trained_input_sizeinmodels/base/model.py, and_square_fallback_for_restored_rectinexport/exporter.py.Verified: 7677 unit tests pass; the 3 failures (DETR ONNX parity on macOS) also fail on clean dev. New tests fail on dev except the ones pinning unchanged behavior (square checkpoints, explicit rectangular export still raising). CPU probes on yolo9/yolo9_p2/yolo9_e2e/yolox/yolo7/rtmdet/picodet: predict, batch, numpy, val, val(augment=True), info, save/reload, ONNX export, track all pass. End-to-end YOLO9t and YOLOX-n: train at (192, 320), val, reload, retrain square.
Not verified: GPU, non-ONNX export formats end to end (fallback covered by unit tests only), RKNN (resolves imgsz itself; unchanged from dev).
Opened by an agent.
Code provenance
Original code written for this PR; bug fixes to LibreYOLO's own first-party code, no third-party code ported, adapted, or introduced; no GPL/AGPL/LGPL/non-commercial/unknown-license material involved.
The PR appears safe to merge; no outstanding finding or new actionable regression was established.
Summary
Restores rectangular checkpoint input sizes for prediction, validation, and export.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Checkpoint imgsz_h and imgsz_w] --> B[Restore model input size] B --> C[Predict and validate at restored size] B --> D{Export supports rectangle?} D -->|Yes| E[Export rectangular canvas] D -->|No, default size| F[Warn and export long-side square]Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/dev..."