From 6a762564c80c2aa2855459c5b2e85846692b8ae8 Mon Sep 17 00:00:00 2001 From: Laughing <61612323+Laughing-q@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:00:24 +0800 Subject: [PATCH] Enable model.eval() usage for `YOLO` class (#17754) --- ultralytics/engine/model.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ultralytics/engine/model.py b/ultralytics/engine/model.py index 71817672..667b54eb 100644 --- a/ultralytics/engine/model.py +++ b/ultralytics/engine/model.py @@ -1126,3 +1126,20 @@ class Model(nn.Module): description of the expected behavior and structure. """ raise NotImplementedError("Please provide task map for your model!") + + def eval(self): + """ + Sets the model to evaluation mode. + + This method changes the model's mode to evaluation, which affects layers like dropout and batch normalization + that behave differently during training and evaluation. + + Returns: + (Model): The model instance with evaluation mode set. + + Examples: + >> model = YOLO("yolo11n.pt") + >> model.eval() + """ + self.model.eval() + return self