Skip to main content

YOLOv5 X W&B in Agriculture

Training a YOLOv5 object detection model to detect images of fruits on a synthetically generated dataset.
Created on February 28|Last edited on February 28

Introduction

The ability to detect fruits (and other crops) can be very important when it comes to counting them and, thus, estimating the the magnitude of the harvest. It can also be useful when estimating which trees produce different fruits and how many.
In this report we're looking at training a custom object detection model to detect images of fruit on a dataset that was synthetically generated, and using Weights & Biases to track the training progress.

Experiment tracking

Weights & Biases offers its users (for personal use or in teams) a project dashboard which contains all of the data of your machine learning training pipeline.

Here we are looking at interactive charts showing accuracy going up and loss going down synced from the project dashboard to this report.

Run set
2


System metrics

Weights & Biases also automatically logs all sorts of system metrics, so that you can make sure that you're utilizing your hardware to its fullest.
Below, you can see the blue run being a larger YOLOv5 model configuration taking up more GPU utilization than the smaller red one.

Run set
2


Metadata

It's also really important to note that Weights & Biases tracks the hyperparameters (like batch size or the number of epochs) and other metadata that you specify for each run. This way, you can see which models are performing best and which hyperparameters they use to do so.



Bounding box debugger

This chart is really one-of-a-kind as it allows to interactive explore model predictions on 16 random images from the validation dataset, and it's also interactive! You can go and adjust the confidence threshold for the bounding boxes being drawn, which classes are being shown and at what epoch during training do we want to see the predictions.
This can be really powerful when understanding the training progress of training specific models as you don't have to now solely rely raw numbers to understand the model performance and can interactively explore the actual predictions.

Run set
1


W&B Tables

Tables is a really powerful tool for exploring tabular data, which supports all sorts of different formats that you can add to it: images, audio, text, video, molecule views and many more.
Here we are one-upping what we did with the bounding box debugger chart above and logging model predictions on all validation images for every epoch. Below, you can compare model predictions under the prediction column and the actual labels under ground truth.
You can use string ops & sorting by different confidence scores to interactively explore model predictions.

Run set
2


Artifacts

Weights & Biases Artifacts is a tool for versioning your models and datasets. Here's how it's used when training a custom object detector.
For each of the training sessions we are logging model checkpoint weights as Artifacts. This way, after we identify which model performs best, we can always go back and find the exact model weights that we need.

Also, we're using Artifacts to version the dataset that we're using for training, if we change a single file it will logged as a newer version of our dataset (without duplicating files in storage).
And we're logging our dataset as a W&B Table also which allows to visualize it and interactively explore as well.


Conclusion

Computer vision can be a powerful driver in the present & future of agriculture allowing us to sustainably produce food that all of us can enjoy. In this report we have looked at how we can use Weights & Biases to facilitate the process of training such deep learning computer vision models.
These detection models can be used for counting different types of crops and adjusting the agriculture processes to be better optimized for the growth of such crops.

Resources