Seed Kernel Counting using Domain Randomization and Object Tracking
  Neural Networks
High-throughput phenotyping (HTP) of seeds, also known as seed phenotyping,
is the comprehensive assessment of complex seed traits such as growth,
development, tolerance, resistance, ecology, yield, and the measurement of
parameters that form more complex traits. One of the key aspects of seed
phenotyping is cereal yield estimation that the seed production industry relies
upon to conduct their business. While mechanized seed kernel counters are
available in the market currently, they are often priced high and sometimes
outside the range of small scale seed production firms' affordability. The
development of object tracking neural network models such as You Only Look Once
(YOLO) enables computer scientists to design algorithms that can estimate
cereal yield inexpensively. The key bottleneck with neural network models is
that they require a plethora of labelled training data before they can be put
to task. We demonstrate that the use of synthetic imagery serves as a feasible
substitute to train neural networks for object tracking that includes the tasks
of object classification and detection. Furthermore, we propose a seed kernel
counter that uses a low-cost mechanical hopper, trained YOLOv8 neural network
model, and object tracking algorithms on StrongSORT and ByteTrack to estimate
cereal yield from videos. The experiment yields a seed kernel count with an
accuracy of 95.2\% and 93.2\% for Soy and Wheat respectively using the
StrongSORT algorithm, and an accuray of 96.8\% and 92.4\% for Soy and Wheat
respectively using the ByteTrack algorithm.
Venkat Margapuri, Prapti Thapaliya, Mitchell Neilsen
# Seed Kernel Counting using Domain Randomization and Object Tracking Neural Networks

###### Abstract

High-throughput phenotyping (HTP) of seeds, also known as seed phenotyping, is the comprehensive assessment of complex seed traits such as growth, development, tolerance, resistance, ecology, yield, and the measurement of parameters that form more complex traits [1]. One of the key aspects of seed phenotyping is cereal yield estimation that the seed production industry relies upon to conduct their business. While mechanized seed kernel counters are available in the market currently, they are often priced high and sometimes outside the range of small scale seed production firms' affordability. The development of object tracking neural network models such as Von Only Look Once (YOLO) enables computer scientists to design algorithms that can estimate cereal yield inexpensively. The key bottleneck with neural network models is that they require a plethora of labelled training data before they can be put to task. We demonstrate that the use of synthetic imagery serves as a feasible substitute to train neural networks for object tracking that includes the tasks of object classification and detection. Furthermore, we propose a seed kernel counter that uses a low-cost mechanical hopper, trained YOLOw neural network model, and object tracking algorithms on StrongSORT and ByteTrack to estimate cereal yield from videos. The experiment yields a seed kernel count with an accuracy of 95.2% and 93.2% for Soy and Wheat respectively using the StrongSORT algorithm, and an accuracy of 96.8% and 92.4% for Soy and Wheat respectively using the ByteTrack algorithm.

 YOLOv8, Artificial Intelligence, Domain Randomization, Object Tracking, Seed Counter

## I Introduction

The advent of technology in the field of agriculture commenced over a century ago, and several studies have been conducted since the 1990s to improve upon production efficiency [2]. High-throughput Phenotyping (HTP) of seeds, also known as seed phenotyping, is the comprehensive assessment of complex seed traits such as growth, development, tolerance, resistance, ecology, yield, and the measurement of parameters that form more complex traits [1]. HTP increases the accuracy of measurements while reducing costs through the application of automation, remote sensing, data integration, and experimental design. The current work addresses the aspect of cereal yield estimation, a use case primarily geared toward the seed production industry. In the absence of accurate seed kernel count, seed production firms package bags of seed kernels by weight. However, the weight of seed kernels depends on the external environment. For instance, the weight of the seed kernels increases when they are soaked in water from the moisture they absorb. There is often a discrepancy between the expected and actual number of seed kernels when the customer acquires the seed kernel bags packaged by weight. Packaging seeds by count is tedious when performed by hand, making it infeasible. Seed production firms have to resort to the use of expensive mechanized seed counting machinery to pack seed kernels by count. However, the seed counting machinery, ranging from $500 to $3000, proves too expensive for small scale production firms at times, and deters them the ability to pack by count.

The significant developments made in the field of Artificial Neural Networks, specifically Object Tracking Neural Network models, enable plant and computer scientists to collaboratively develop low-cost, high-throughput systems for seed kernel counting. This paper demonstrates the idea of leveraging videos of seed kernels rolling down a platform to estimate seed kernel count using low-cost hardware components (described in section II) and the object tracking neural network model of You Only Look Once (YOLO). YOLO belongs to a class of supervised neural networks that provides object tracking ability. The task of object tracking bundles the tasks of object detection and classification within it. Supervised neural network models require a plethora of labelled information to train for tasks such as object detection and classification. However, labelled training data is not always readily available for entities such as seed kernels. We demonstrate that the use of synthetic image datasets, generated following the principles of Domain Randomization [3, 4, 5], is a feasible alternative to train neural network models in the absence of real-world labelled datasets.

## II Related Work

Neilsen et al. [6] proposed an image processing algorithm to conduct seed kernel counting from videos. The working of the algorithm is based on tracking each of the seed kernels as they flow down a backlit platform. A seed kernel is considered a valid detection and counted if the seed kernel is detected a predefined number of times (threshold). However, the image processing algorithm is highly sensitive to the video's frame
rate.

GridFree [7] is a Python package for image analysis of interactive grain counting and measurement. GridFree uses an unsupervised machine learning approach, K-Means, to segment kernels from the background by using principal component analysis (PCA) on both raw image channels and their color indices. The package incorporates users' experiences as a dynamic criterion to set thresholds for a divide-and-combine strategy that effectively segments adjacent kernels. When adjacent multiple kernels are incorrectly segmented as a single object, they form an outlier on the distribution plot of kernel area, length, and width. The software exhibits great performance on multiple crop types such as alfalfa, canola, lentil, wheat, chickpea, and soybean.

Parico et al. [8] performed real-time pear fruit detection and counting using YOLOv4 models and Deep SORT algorithm. The study provides a systematic and pragmatic methodology to choose the most suitable neural network model for a desired application in the field of agriculture. The region-of-interest (ROI) line technique was used by the study to estimate the number of pear fruits detected by the neural network model.

Wu et. al. [9] performed detection of Camellia oleifera fruit in complex scenes by using YOLOv7 and data augmentation. The comparison of YOLOv7's performance with YOLOv5, YOLOv3-spp, and Faster RCNN showed that YOLOv7 provided the best detection performance. The experiment yielded a Mean Average Precision, Precision, Recall, F1 Score, and average detection time of 96.03%, 94.76%, 95.54%, 95.15%, and 0.025 seconds per image respectively.

Hajar et al. [10] performed vision-based moving obstacle detection and tracking in paddy field using YOLOv3 and Deep SORT. The center point positions of the obstacles were used to track the objects as they moved through the paddy field. The augmented YOLOv3 architecture consisted of 23 residual blocks and up-sampled only once. The augmented architecture obtained a mean intersection over union score of 0.779 and was 27.3% faster in processing speed than standard YOLOv3.

Huang et al. [11] developed a video-based detection model to identify damage within unwashed eggs using YOLOv5 and ByteTrack object tracking algorithm. The detection results of the different frames were associated by ID, and used five different frames to determine egg category. The experimental results showed an accuracy of 96.4% when YOLOv5 in conjunction with the ByteTrack algorithm was used to detect broken/damaged eggs from videos.

## III Hardware Components

We propose a low-cost setup for the capture of seed kernel videos for algorithmic analysis using YOLOv8. Fig. 1 shows the seed kernel image capture setup designed for the experiment. The mechanical hopper helps to deliver seeds at a constant rate unlike free-hand delivery that tends to be erratic. The mobile phone is placed on a 3-D printed stand to ensure that the camera is always held orthogonal to the surface. It helps to eliminate any skew that may result during the capture of the video. The stand is fitted with a 3-D printed platform at the bottom. The platform at the bottom channels the seed kernels ensures that the seed kernels remain in the field of view of the camera as they roll down the light box. In the absence of the platform, it is observed that seed kernels often drift to the side and fall off the light box prematurely, hindering their detection. The mobile phone used for image capture is a Google Pixel 2 XL mobile phone whose default capture frame rate is 60 fps. Fig. 2 shows a frame of the wheat seed kernel video captured using the proposed setup in Fig. 1.

## IV Domain Randomization and Image Datasets

Domain Randomization (DR) is the idea of training neural network models on images containing simulated objects that translate closely to real-world objects. A small sample of images containing real objects is required for the creation of synthetic images using DR. The images of soy and wheat are captured by placing a mobile phone on a 3-D printed stand that holds the mobile phone orthogonal to the surface. Ensuring

Fig. 1: Mechanical hopper delivering seed kernels
that the mobile phone is held orthogonal to the surface is key to eliminate any skew in the resulting images. Fig. 4 shows soy seeds being captured by the proposed image capture setup.

Images of 25 seed kernels of soy and wheat are captured using the setup shown in Fig. 3. Using the synthetic image generator developed as part of a previous work [3] synthetic images containing seed kernels of soy and wheat are developed. The synthetic image generator applies image augmentation techniques such as rotation, flipping, and noising to generate image datasets that are akin to real-world scenarios. The synthetic images are meticulously curated to allow for about 25% overlap at the maximum to account for clustered seed kernels as the frames of the video are processed. Synthetic image datasets are created for the seed types of soy and wheat, wherein each dataset consists of 200 images of size 320x320x3 with each image containing between 25 and 50 seed kernels overlaid on a light background, as shown in Fig. 4. Furthermore, the synthetic image generator outputs annotation files that contain location coordinates pertinent to each seed kernel in the image in the TXT format for YOLOv8 to consume and process during training. In addition to the 200 images of each seed kernel type generated for training YOLOv8, 35 synthetic images containing 30 seed kernels of each seed kernel type are generated for testing on YOLOv8.

## V YOLOv8 and Object Tracking Algorithms

The YOLO model is a single-shot detector [12, 13, 14] that uses a fully convolutional neural network as the backbone to process the input image. The YOLOv8 [15] model used for this work was released in January 2023 by Ultralytics to support multiple computer vision tasks such as object detection, classification, segmentation, pose estimation, and tracking. YOLOv8 comprises a convolutional neural network that is divided into two parts: backbone and head. The backbone, CSPDarknet53 [16], consists of 53 convolutional layers and uses cross state partial connections to facilitate information flow between different layers. The head consists of multiple convolutional layers followed by a series of fully connected layers. Another key characteristic of YOLOv8 is the use of the Self-Attention [17, 18] mechanism in the head to enable the model to focus on specific parts of the image for better performance.

Object tracking involves the tasks of object detection and classification, and feature mapping between objects in different frames as they move around. YOLOv8 is a single-shot object detector that detects and labels objects in a given image. However, object tracking requires that the object be detected in every frame across the video i.e. the object is to be re-identified within every frame as each frame of the video gets processed. Several object tracking algorithms [19, 20, 21] have been proposed over the years. This paper considers two object tracking algorithms for experimentation, namely, StrongSORT and ByteTrack.

### _StrongSORT_

The StrongSORT [19] algorithm is an improvement over the DeepSORT [20] algorithm. StrongSORT algorithm, like DeepSORT, is a two-branch framework consisting of an Appearance branch and a Motion branch. The algorithm works on objects that have been detected in each frame of the video. The YOLOX-X [21] model is used to detect the objects in the frame. However, detections may be performed using alternate

Fig. 4: Image capture of soy seed kernels

Fig. 3: Image capture of soy seed kernels

Fig. 2: Wheat seed kernels flowing down the light box
object detectors such as Faster R-CNN [24] as well.

The Appearance branch identifies the features of each of the objects detected in a given frame. The detected features are used to match a given object across different frames. BoT [22] is leveraged as the feature extractor by the StrongSORT algorithm. The appearance state for the \(i^{th}\) tracklet within frame t, \(e_{i}^{t}\), is updated as the exponential moving average (EMA) given by \(e_{i}^{t}\) = \(\alpha e_{i}^{t-1}\) + (1-\(\alpha\))\(f_{i}^{t}\) where \(f_{i}^{t}\) is the appearance embedding of the current matched detection and \(\alpha\) = 0.9, is a variable momentum term. The benefit of EMA lies in the fact that it leverages information of inter-frame feature changes and suppresses detection noise.

The Motion branch leverages Kalman Filter [25] to predict the position of the object in the frame based on a constant velocity model. However, the basic Kalman Filter offers poor performance when the detections made by the object detector are sub par. In order to tackle this issue, the StrongSORT algorithm uses the NSA Kalman Filter algorithm borrowed from the GIAO tracker [26].

### _ByteTrack_

ByteTrack [23] algorithm is best suited to cases where objects detected in one frame of the video by detectors such as YOLOv8 are ignored in a different frame of the video. Such instances are generally a result of occlusion of objects as they move from one frame to the other. Motion tracking (MoT) algorithms typically leverage bounding boxes plotted by object detectors (such as YOLOv8) to assign a unique ID to each object in the video. Furthermore, object detectors associate a confidence level to each bounding box that is plotted. Most MoT algorithms ignore bounding boxes that have a confidence level below a threshold to avoid false positives. However, ignoring the bounding boxes at low confidence levels risks ignoring detecting objects that may otherwise be detected (true positives). The ByteTrack algorithm mitigates the risk by leveraging bounding boxes at all confidence levels agnostic of a confidence level threshold and meticulously attempts to identify all objects in a frame agnostic of the detection confidence level.

The ByteTrack algorithm leverages a queue called Tracklets to store all the objects (and bounding boxes) that have been detected by the object detector (YOLOv8). The bounding boxes are separated into high score (\(D^{high}\)) and low score (\(D^{low}\)) based on threshold. Each of the objects in the Tracklets queue is tracked across each frame of the video agnostic of the confidence level of the bounding boxes associated to them. The tracking of objects across frames is performed using Kalman Filter [25]. Firstly, the position (bounding box) of each of the objects in the tracklets queue is predicted in the subsequent frame. The predictions are matched with the actual detections made by the object detector using Motion Similarity score. Motion Similarity score is computed as the result of Intersection over Union (IoU) between the predicted and actual bounding boxes. Initially, tracklet matching is done between the predicted and high score (\(D^{high}\)) bounding boxes. The tracklets that do not match with any of the high score bounding boxes are matched with low score (\(D^{low}\)) bounding boxes. Any tracklet that is not matched is preserved for a predefined number of frames to test for rebirth in case of occlusion. Finally, the tracklet is removed from the queue if a match is never found.

## VI Experiment

The development of the Seed Counter using YOLOv8 and object tracking algorithms involves three steps:

* Seed detection
* Seed tracking
* Seed counting

### _Seed Detection_

The YOLOv8 model is trained on the image dataset generated using the synthetic image generator (described in section IV). 80% of the image dataset is used for training and 20% is used for validation. The model is tested on images containing real Soy and Wheat seed kernels. The test dataset consists of 100 images, 50 of soy and 50 of wheat, each containing 20-30 seed kernels. Transfer Learning [], the ability of a neural network to apply the knowledge gained by training on a dataset to a different dataset where there is a presence of common domains between the source and target datasets, is leveraged to train the YOLOv8 model. Model weights from the YOLOv8 model pretrained on the COCO image dataset are leveraged as provided by Uralytics. The hyperparameters used to train the YOLOv8 model are as shown in Table I. The results of seed kernel detection on the test dataset are evaluated using the metrics of Precision, Recall, and Average Precision (PR). The metrics are briefly described below and the obtained results are presented in Table II.

**Precision:** Precision indicates the number of positives accurately classified by the classifier from all the classifications made. It is given by _true positives/ (true positives + false positives)_.

**Recall:** Recall indicates the number of positives identified by the classifier of all the positives present in the dataset. It is given by _true positives/(true positives + false negatives)_.

**Average Precision:** The Average Precision is computed as the ratio of the Intersection-over-Union (IoU) between the bounding box predictions made by the classifier and ground
truth bounding boxes. It is computed for an 50% overlap between ground truth and predicted bounding boxes for the purposes of this paper, given by \(AP_{50}\).

**Note:** Average Precision is only reported for the validation data set but not test data set because the images in the test set do not have ground truth bounding boxes plotted around them.

From the results in table II, high recall scores of 91% and 90% on soy and wheat respectively for the test set indicates that the model albeit being trained on synthetic images detects real seed kernels well. The precision scores of 93% and 92% indicate that the model classifies the seed kernels correctly on most instances. The reason for high precision might be due to the clear morphometric distinction between soy and wheat.

### _Seed Tracking_

The Seed Tracking phase involves the application of StrongSORT and ByteTrack algorithms to videos of Soy and Wheat seed kernels captured using the setup described in section III. The experiment is conducted on videos containing 250 seed kernels of each seed type captured at three different frame rates, 30, 60, and 120 i.e. normal speed, slow motion, and super slow motion. Videos with higher frame rates capture more level of detail than those with lower frame rates. Frame rate has a significant impact on object tracking algorithms since they function by predicting the position of objects in future frames. The StrongSORT and ByteTrack algorithms are applied using the detection weights obtained in the Seed Detection phase as input. The tracking algorithms apply a unique ID to each seed kernel detected in the video and track them throughout the video. In the perfect world where the seed kernels in the video are not prone to occlusion or clustering, mere tracking of objects in the video and counting the number of IDs tracked by the object tracking algorithm is sufficient to obtain a count of the seed kernels in the video. However, the seed kernels in the video are clustered in parts, occluded, and prone to sudden deviations in trajectory, as shown in Fig. 2. The aforementioned issues of clustering, occlusion, and sudden trajectory deviations lead to the risk of object tracking algorithms assigning different unique IDs to the same seed kernel in different frames of the video, eventually leading to a discrepancy between the actual number of seed kernels in the video and number of unique IDs generated by the object tracking algorithms. The number of unique IDs generated by StrongSORT and ByteTrack algorithms on each of the videos captured for the wheat seeds are shown in Tables III and IV respectively. The results show that either of the object tracking algorithms consistently overcount the number of seed kernels in the video.
rate of 30 and least accurate on videos captured at a frame rate of 120 for either seed type, and object tracking algorithm demonstrating that a lower frame that captures a higher level of detail positively influences the performance of object tracking algorithms. However, both algorithms undercount the number of seed kernels agnostic of frame rate. It is due to clustering of seed kernels in certain frames which results in the seed tracking algorithms considering multiple seed kernels as one.

## VII Pitfalls, Future Work, and Conclusion

The key pitfall of the experiment is that the videos used for the experiment consist of seed kernels that are clustered. As a result, the object tracking algorithms failed to track each seed kernel accurately. In further experiments, the video capture mechanism will be altered to ensure that the videos do not contain clustered (or occluded) seed kernels.

Overall, the experiment demonstrates the feasibility of synthetic images to train object tracking neural network models, and their application in seed kernel counting aimed at the seed production industry. As the results are encouraging, future work will involve the development of a mobile application (Android/iOS) and a robust video capture mechanism.
