ultralytics / ultralytics

NEW - YOLOv8 πŸš€ in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
24.46k stars 4.86k forks source link

yolov8 detection on small objects #12757

Open echo385 opened 2 weeks ago

echo385 commented 2 weeks ago

Search before asking

Question

First thank you for your contribution! This is my target distribution, can I consider this is a small target? Currently, the size of my training images are all 640*640, but I use a 1280-size model to train better than a 640-size model. Why is this? If increasing the resolution of the model has an effect, can I continue to increase the model size, such as 2560, for training? labels

Additional

No response

glenn-jocher commented 2 weeks ago

@echo385 hello! It's great to hear you're exploring YOLOv8 for detecting small objects. 😊

Increasing the model size can indeed help improve the detection of smaller objects, as a larger model generally has more capacity to learn detailed features. Using a model resolution higher than your training data resolution (like using 1280 when training images are 640*640) allows the model to learn finer details by internally upscaling the images.

You can experiment with increasing the model size further to 2560, but keep in mind that this will also increase the computation requirement significantly. It might be beneficial, especially if your targets are very small relative to the image size. However, watch out for diminishing returns in accuracy improvement versus the computational cost.

Here's a small tweak in training settings you might want to try:

from ultralytics import YOLO

# Assuming yolov8n model for example
model = YOLO('yolov8n.pt')

# Training with increased image size
results = model.train(data='data.yaml', epochs=100, imgsz=2560)

Keep observing the model's performance as you scale up. Good luck and happy detecting! πŸš€

echo385 commented 2 weeks ago

@echo385 hello! It's great to hear you're exploring YOLOv8 for detecting small objects. 😊

Increasing the model size can indeed help improve the detection of smaller objects, as a larger model generally has more capacity to learn detailed features. Using a model resolution higher than your training data resolution (like using 1280 when training images are 640*640) allows the model to learn finer details by internally upscaling the images.

You can experiment with increasing the model size further to 2560, but keep in mind that this will also increase the computation requirement significantly. It might be beneficial, especially if your targets are very small relative to the image size. However, watch out for diminishing returns in accuracy improvement versus the computational cost.

Here's a small tweak in training settings you might want to try:

from ultralytics import YOLO

# Assuming yolov8n model for example
model = YOLO('yolov8n.pt')

# Training with increased image size
results = model.train(data='data.yaml', epochs=100, imgsz=2560)

Keep observing the model's performance as you scale up. Good luck and happy detecting! πŸš€

thank you for your reply! So how can I improve the accuracy and recall rate of the model in detecting small targets?

echo385 commented 1 week ago

thank you for your reply! So how can I improve the accuracy and recall rate of the model in detecting small targets?

@echo385 hello! It's great to hear you're exploring YOLOv8 for detecting small objects. 😊

Increasing the model size can indeed help improve the detection of smaller objects, as a larger model generally has more capacity to learn detailed features. Using a model resolution higher than your training data resolution (like using 1280 when training images are 640*640) allows the model to learn finer details by internally upscaling the images.

You can experiment with increasing the model size further to 2560, but keep in mind that this will also increase the computation requirement significantly. It might be beneficial, especially if your targets are very small relative to the image size. However, watch out for diminishing returns in accuracy improvement versus the computational cost.

Here's a small tweak in training settings you might want to try:

from ultralytics import YOLO

# Assuming yolov8n model for example
model = YOLO('yolov8n.pt')

# Training with increased image size
results = model.train(data='data.yaml', epochs=100, imgsz=2560)

Keep observing the model's performance as you scale up. Good luck and happy detecting! πŸš€

thank you for your reply! So how can I improve the accuracy and recall rate of the model in detecting small targets?

echo385 commented 1 week ago

thank you for your reply! So how can I improve the accuracy and recall rate of the model in detecting small targets?

glenn-jocher commented 1 week ago

Hello @echo385! To enhance the accuracy and recall for small objects, you might consider these strategies:

  1. Adjust Anchor Boxes: Customize anchor boxes to better match the size distribution of your small targets. This can be done by analyzing the common dimensions of your small objects and adjusting the anchor box sizes accordingly in your model configuration.

  2. Data Augmentation: Increase the variety of small object appearances in your training data through augmentation techniques like random scaling, cropping, and flipping. This helps the model generalize better over small objects.

  3. Fine-tuning: If you're using a pre-trained model, fine-tuning it on a dataset that includes many small objects can significantly improve its performance on those objects.

  4. Focus Loss: Implement or adjust focus loss functions that penalize incorrect predictions more on smaller objects.

Here’s a quick example of how you might adjust anchor boxes in your configuration file:

anchors: 3
anchor_grid: [[10,13, 16,30, 33,23], [30,61, 62,45, 59,119], [116,90, 156,198, 373,326]]

Adjust the values based on your specific small object sizes. Keep experimenting with these settings to find the best configuration for your use case! πŸš€