Cannot compute loss function from best model
useruser2023 opened this issue · 1 comments
Search before asking
- I have searched the YOLOv3 issues and found no similar bug report.
YOLOv3 Component
Validation
Bug
I need to pass the loss function in order to run val.py for validation. After training on two classes, we chose the best automatically produced model for inference. Used this approach
Environment
- Yolov3-Tiny
Minimal Reproducible Example
from utils.loss import ComputeLoss
from ultralytics import YOLO
model = YOLO("best.pt")
comput_loss = ComputeLoss(model.model)
Additional
AttributeError: 'DetectionModel' object has no attribute 'hyp'
Are you willing to submit a PR?
- Yes I'd like to help by submitting a PR!
@useruser2023 hello! Thanks for reaching out and for your efforts in searching for a solution before posting your issue.
The error you're encountering, AttributeError: 'DetectionModel' object has no attribute 'hyp'
, suggests that the model object you're trying to use does not have the hyperparameters (hyp
) attribute that the ComputeLoss
function expects.
The ComputeLoss
function requires the model's hyperparameters to calculate the loss. When you load the model using YOLO("best.pt")
, it does not automatically load the hyperparameters used during training.
To resolve this, you should ensure that the hyperparameters are correctly loaded and associated with your model object. Typically, these hyperparameters are stored in a .yaml
file or within the training script. Make sure to load these hyperparameters and pass them to the ComputeLoss
function or the model object as required.
For further guidance on how to properly set up the loss computation for validation, please refer to the Ultralytics Docs, which provide comprehensive information on using the YOLOv3 repository.
If you continue to face issues, please provide more details about how you're loading the model and where the hyperparameters are defined, and we'll be happy to help you further. Remember, the community and the Ultralytics team are here to support you! 😊