Fix bugs and dead code across repo (#13762)
* Fix bugs and dead code across repo
Repo-wide bug scan: each change is a real bug fix or dead code removal,
no new abstractions, no defensive validation for impossible states.
Bugs:
- utils/general.py: Windows logger lambda captured fn by reference (late
binding) so LOGGER.info ended up calling LOGGER.warning. Use default arg.
- utils/augmentations.py: LetterBox auto-mode `hs, ws = genexp if ... else
self.h, self.w` parsed as `(genexp), self.w`, leaving hs as a generator.
Parenthesize the tuple branches.
- utils/loggers/comet/__init__.py: `raise "<string>"` is a TypeError in
Python 3 — promote to ValueError.
- models/common.py: TensorRT dynamic-shape path called `data.resize_()`
on output bindings without refreshing binding_addrs, so execute_v2 ran
against stale pointers if the tensor reallocated. Refresh after resize_.
- export.py: TFLite export leaked a file handle (open().write()).
- export.py: opset run() default (12) didn't match CLI default (17).
- benchmarks.py: `if map` referenced the Python builtin (always truthy);
the alternate branch was unreachable. Drop the dead conditional.
- detect.py: CSV label ternary `names[c] if hide_conf else f"{names[c]}"`
produced the same string in both branches.
Dead code / cleanup:
- val.py: commented-out duplicate argsort.
- export.py: redundant `weights_dir = None` overwritten on the next line.
- utils/loggers/comet/__init__.py: unreachable bare `return`.
- utils/segment/plots.py: commented-out matplotlib code referencing a
non-existent API.
Perf:
- classify/predict.py: `torch.Tensor(im).to(device)` allocates on CPU then
copies; switch to `torch.from_numpy(im).to(device)` to skip the CPU copy.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Auto-format by https://ultralytics.com/actions
* Revert two changes that caused CI regressions
- classify/predict.py: torch.Tensor(im) accepts both numpy arrays and
Tensors; the dataset already calls ToTensor() so im is a Tensor by the
time it reaches this line. torch.from_numpy rejects Tensors with
'TypeError: expected np.ndarray'. Restore torch.Tensor.
- export.py: restore run() opset default to 12 to match prior behavior;
the CLI default of 17 was already correct on master.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com> G
Glenn Jocher committed
781d9c4ef73ae9b640f859f9799c3010135a1e2d
Parent: 6c66ecd
Committed by GitHub <noreply@github.com>
on 5/2/2026, 1:22:59 PM