A project for detecting wheat heads in images using the YOLO11n model from Ultralytics. This repository includes dataset setup, model training, and inference with visualization for the GlobalWheat2020 dataset. π
This project leverages the power of the YOLO11n model to detect wheat heads in agricultural images. It uses the GlobalWheat2020 dataset, automates dataset organization, trains a model, and performs inference with visualized bounding boxes. Perfect for computer vision enthusiasts and agricultural tech researchers! πΈ
- π οΈ Installs Ultralytics for YOLO model support
- π Downloads and organizes the GlobalWheat2020 dataset
- βοΈ Trains YOLO11n for wheat head detection
- πΌοΈ Visualizes detection results with bounding boxes
- π Supports further training and inference
- Clone the repository:
git clone https://github.com/shahin-ro/wheat-detection.git cd wheat-detection - Install dependencies:
pip install ultralytics
Note: This project is designed to run in a Google Colab environment for easy access to GPU resources. Adjust paths if running locally.
The project uses the GlobalWheat2020 dataset. The script:
- Downloads images and annotations
- Organizes them into
images,annotations, andlabelsdirectories - Creates a
GlobalWheat2020_subset.yamlfile for training and validation subsets
- Setup: Run the dataset setup code to download and organize the GlobalWheat2020 dataset.
- Train: Train the YOLO11n model using the provided YAML configuration.
- Infer: Upload an image and detect wheat heads with visualized results.
Train the model with the following command in the script:
model = YOLO("yolo11n.pt")
model.train(data="GlobalWheat2020_subset.yaml", epochs=5, imgsz=640)- Adjust
epochsorimgszfor better results. - Trained weights are saved in
/content/runs/detect/train/weights/best.pt.
Perform inference on a new image:
model = YOLO("/content/runs/detect/train/weights/best.pt")
results = model("path/to/your/image.jpg")
for result in results:
img = result.plot()
plt.imshow(img)
plt.axis('off')
plt.show()Upload an image in Colab to see bounding boxes around detected wheat heads.
The model outputs bounding boxes around wheat heads in the input images. Results are visualized using Matplotlib, showing detected wheat heads with confidence scores.
Contributions are welcome! π
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit changes (
git commit -m 'Add YourFeature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
πΎ Happy wheat detection! If you find this project useful, give it a β on GitHub!