Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to optimize #12719

Open
1 task done
monkeycc opened this issue May 16, 2024 · 5 comments
Open
1 task done

How to optimize #12719

monkeycc opened this issue May 16, 2024 · 5 comments
Labels
question Further information is requested

Comments

@monkeycc
Copy link

monkeycc commented May 16, 2024

Search before asking

Question

yolov8s-seg.pt

imgsz=1280 , epochs=100, flipud = 0.5 , fliplr = 0.5

Additional

No response

@monkeycc monkeycc added the question Further information is requested label May 16, 2024
@glenn-jocher
Copy link
Member

It looks like you're trying to optimize the model training parameters! For the given yolov8s-seg.pt model with an image size of 1280, you might consider the following:

  • Adjust Learning Rate: Sometimes slight adjustments to the learning rate can yield better optimization results. If you haven't already, experiment with changing the learning rate (lr0) slightly higher or lower.

  • Data Augmentation: Your current settings already include flipping. Consider adding other augmentations like color jitter, rotation, etc., if not already included.

  • Batch Size: If hardware allows, increasing the batch size can sometimes improve the results, as it provides more stable gradient estimates during training.

An example command might look like this:

yolo train data=coco.yaml model=yolov8s-seg.pt imgsz=1280 epochs=100 flipud=0.5 fliplr=0.5 lr0=0.01 mosaic=0.1 mixup=0.2

Adjust the additional augmentation parameters (mosaic and mixup) as needed. Be sure to carefully monitor your system's memory and processing capabilities when adjusting these parameters. Good luck with your optimizations! 🚀

@monkeycc
Copy link
Author

monkeycc commented May 16, 2024

Thank you, very valuable for reference

The problem has been resolved
But I'm not sure why this is happening
My train model is 1280
imgsz=1280

But when reasoning, it must be 640 to avoid any problems

model.predict('bus.jpg', save=True, imgsz=640 )

@glenn-jocher
Copy link
Member

@monkeycc i'm glad to hear that your problem is resolved! 🎉 Regarding your question, the discrepancy you're seeing in image sizes between training and inference typically relates to the model's handling of different input dimensions.

During training (imgsz=1280), your model learns features at a higher resolution, which is great for accuracy. However, at inference time, using a smaller image size (imgsz=640) can help speed up the process with less computational demand, albeit sometimes at the cost of some accuracy. It’s like a balance between performance and speed.

Here's the key: make sure the inference image size (imgsz) is the same or smaller than the training size to avoid errors, since upsampling during inference can introduce issues if the model has never seen higher resolutions during training. You got it right by using 640 for inference! 👍

If you need to maintain both high accuracy and performance during inference, you might consider retraining your model at a lower imgsz or optimizing your model further. Let me know if you need help with that!

@monkeycc
Copy link
Author

Training model
imgsz=1280

predict
imgsz=640
normal

predict
imgsz=1280
There is an issue with the recognition rate!

What is the reason
Shouldn't we also use imgsz=1280 for predict

@glenn-jocher
Copy link
Member

Hi there! It seems like you're encountering a drop in recognition rate when using imgsz=1280 during prediction, compared to imgsz=640.

This could be due to a few factors:

  1. Model Adaptation: If your model was primarily validated and tested with imgsz=640, it might perform better at this size. Models can be sensitive to the input size, especially if they were not extensively validated at larger sizes during training.

  2. Overfitting to Training Size: The model might be overfitting to a smaller size if during training and validation, imgsz=640 was used mostly. It is usually a good practice to train and validate the model on the size you intend to use during production to ensure optimal performance.

  3. Computational Constraints: Higher image sizes increase computational demand, which might affect performance if not managed properly.

For consistency and performance, it’s generally recommended to use the same image size for training and prediction. If imgsz=1280 gives issues, you might want to retrain your model specifically for this size, ensuring all augmentation and validation steps are aligned with this dimension.

Here's a quick check you can do in prediction:

model = YOLO('path/to/model.pt')
results = model.predict('path/to/image.jpg', imgsz=1280)  # test at high resolution
print(results.xyxy)

Hope this helps! Let me know if you have more questions. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants