Improving Small Object Detection in Large Images Using Tiling
Search before asking
- [x] I have searched the YOLOv5 issues and discussions and found no similar questions.
Question
Description I am working on detecting very small objects (e.g., screws) within large images (~4000x3000 pixels) of a perforated tank. However, I am facing challenges with low detection accuracy, likely due to the small object size relative to the full image.
I believe tiling could be a good solution, but I am unsure of the best approach to integrate it into the training pipeline. Specifically:
Should I label the full images first and then apply tiling, or should labeling be done after tiling? What is the recommended way to ensure consistency between tiles and the original annotations? Are there any best practices or existing implementations that could help with tiling for small object detection? Any guidance, references, or example scripts would be greatly appreciated.
Context Image Size: ~4000x3000 Objects: Very small (screws, etc.) Model: YOLO-based detection (but open to suggestions) Thank you in advance for your help! π
Additional
No response
π Hello @Uddeshya1052, thank you for your interest in YOLOv5 π! It sounds like you're tackling an interesting challenge in small object detection within large images. Please explore the following resources to potentially help address your question:
Resources
- βοΈ Tutorials - Start from our Tutorials to better understand YOLOv5 capabilities, including tips for preparing datasets and optimizing detection.
- Tips for Best Training Results - Learn how to improve model performance through data augmentation and anchoring techniques.
- Discussions - Join the community to exchange tips about small object detection or tiling methods.
Recommendations
If tiling is your planned approach:
- Annotating full images first is generally recommended to ensure all objects are accounted for before splitting into tiles.
- Ensure tiling processes maintain annotation consistencyβeach tile must contain properly mapped labels relative to the objects within it. Open-source tools like
roboflowor custom scripts can automate this step. - Consider data augmentation, ensuring that the tiles resemble diverse real-world conditions and preventing overfitting to specific sizes or resolutions.
As YOLOv5 has high flexibility, you might also experiment with model hyperparameters like anchor sizes or train-scaled variants (e.g., YOLOv5x vs YOLOv5s) for detecting smaller objects πͺ. Check out Hyperparameter Evolution for guidance.
Additional Resources
YOLOv5 may be used in combination with diverse environments where tiling workflows can be implemented:
- Notebooks:
- For automation, consider a Docker Image: See Docker Quickstart Guide
Requirements
Ensure you are running:
- Python>=3.8.0 with all requirements.txt installed
- PyTorch>=1.8
git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
Next Steps
If this is a β Question and you'd like further help, please:
- Share additional details about your current progress, tiling script (if used), or results so far.
- Provide examples of the images and labeling format to better assist.
If this is a π Bug Report regarding YOLOv5 behavior, include a minimum reproducible example (MRE) for debugging.
This is an automated response to assist you efficiently π€. An Ultralytics engineer will review and provide additional guidance soon π. Thank you again for your enthusiasm and for using YOLOv5! π
@Uddeshya1052 for small object detection in large images with YOLOv5, we recommend:
-
Label Full Images First: Annotate the original high-resolution images, then use a tiling script to split both images and labels into smaller tiles (e.g., 640x640). This maintains annotation consistency automatically.
-
Tiling Implementation:
from utils.dataloaders import LoadImagesAndLabels
dataset = LoadImagesAndLabels(path, imgsz=640, augment=True)
# Enable "rectangular training" with mosaic augmentation in your train.py call:
# python train.py --rect --img 640
- Key Adjustments:
- Use
--img 640(or larger) - Reduce anchor sizes in your YAML
- Increase
--iou-thresslightly
For implementation details, see the Ultralytics YOLOv5 documentation on training with mosaic augmentation and rectangular training. This approach effectively handles small objects while maintaining original annotation relationships.
@pderrenger Thank you for your answer! How can I get the tiling script? Is there an official source or example code available?
@Uddeshya1052 for tiling in YOLOv5, we recommend using the built-in LoadImagesAndLabels dataset class with rectangular training (via --rect flag) and mosaic augmentation. This automatically handles image/label tiling during training without needing separate scripts. See the LoadImagesAndLabels implementation and training documentation for details. For custom tiling needs, you can modify this class while maintaining label alignment.
π Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.
For additional resources and information, please see the links below:
- Docs: https://docs.ultralytics.com
- HUB: https://hub.ultralytics.com
- Community: https://community.ultralytics.com
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!
Thank you for your contributions to YOLO π and Vision AI β