Code Refactor for Speed and Readability (#13450)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Paula Derrenger 2024-06-09 17:38:05 +02:00 committed by GitHub
parent 1b26838def
commit 6367ff4748
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 28 deletions

View file

@ -169,12 +169,18 @@ class BasePredictor:
def predict_cli(self, source=None, model=None):
"""
Method used for CLI prediction.
Method used for Command Line Interface (CLI) prediction.
It uses always generator as outputs as not required by CLI mode.
This function is designed to run predictions using the CLI. It sets up the source and model, then processes
the inputs in a streaming manner. This method ensures that no outputs accumulate in memory by consuming the
generator without storing results.
Note:
Do not modify this function or remove the generator. The generator ensures that no outputs are
accumulated in memory, which is critical for preventing memory issues during long-running predictions.
"""
gen = self.stream_inference(source, model)
for _ in gen: # noqa, running CLI inference without accumulating any outputs (do not modify)
for _ in gen: # sourcery skip: remove-empty-nested-block, noqa
pass
def setup_source(self, source):