??AI for Cannabis: Detection and Classification of Cannabis Seeds ??

??AI for Cannabis: Detection and Classification of Cannabis Seeds ??

Cannabis cultivation is subject to strict regulations, particularly concerning the chemical composition of the plant, specifically THC content. Accurate detection and classification of cannabis seeds help ensure compliance with legal thresholds for THC, particularly distinguishing between industrial hemp (low THC) and marijuana (high THC).

In regions where cannabis is legalized for medicinal or recreational use, seed detection can help authorities and producers comply with legal standards.


The cannabis industry relies heavily on product quality and consistency. Detecting and classifying cannabis seeds accurately helps maintain seed purity, which is essential for producing crops with consistent characteristics. This is important for both recreational and medicinal cannabis, where specific strains are cultivated for desired effects or therapeutic properties.        

Cannabis is a genetically diverse plant with numerous subspecies, each offering different medicinal and psychoactive effects. Accurately identifying and classifying seeds based on their variety ensures that the genetic integrity of a strain is maintained across generations, which is crucial for breeding programs and the development of new strains.

To develop seed detection and classification models the following research approaches were considered:


Taxonomy of several seed detection and classification studies. Source: Islam et al., 2024


Advancements and limitations of seed classification and detection in modeling. Source: Islam et al., 2024

Overview of Today's Research Paper


The study presented by a research team from United States ???? two month ago in the paper "Detection and Classification of Cannabis Seeds Using RetinaNet and Faster R-CNN" outlines a deep learning approach to detect and classify 17 varieties of cannabis seeds using advanced models such as RetinaNet and Faster R-CNN. The study utilized a dataset of 3,319 high-resolution images of cannabis seeds and compared the performance of different object detection models to automate seed classification, which has traditionally been labour-intensive and error-prone.


Proposed model workflow for cannabis seed detection and classification. Source: Islam et al., 2024

In the figure above: the process includes data annotation, dataset splitting, and augmentation. The object detection model uses classification and regression layers for seed variety identification and bounding box prediction. Performance is evaluated using IoU, mAP, recall, and F1 score for both detection and classification tasks.


Architecture of the RetinaNet network. Source: Islam et al., 2024

In the figure above: The diagram illustrates the bottom–up pathway (stages 1–4) and the top–down pathway (C2–C4) with 3 × 3 convolution layers producing feature maps P2, P3, and P4. The 2x upsampling block integrates features, resulting in predictions for the input image containing cannabis seeds.

In the figure below: The input image undergoes feature extraction via a ResNet backbone, producing a high-dimensional feature map. This map is subsequently processed by the region proposal network (RPN), which employs sliding window mechanisms to propose candidate object regions. These regions are refined through bounding box regression and softmax classification within the Faster R-CNN module, culminating in precise object detection predictions.

Architecture of the Faster R-CNN network. Source: Islam et al., 2024



1. Dataset Composition

The dataset consisted of 3,319 high-resolution images, categorized into 17 different cannabis seed varieties. The images were captured using an iPhone 13 Pro and annotated with bounding boxes using the Grounding DINO model to automate the labelling process.

Seed varieties included:

  • AK47
  • Blackberry (Auto) (BBA)
  • Cherry Pie (CP)
  • Gelato (GELP)
  • Gorilla Purple (GP)
  • Hang Kra Rog Ku (HKRKU)
  • Hang Kra Rog Phu Phan ST1 (HKRPPST1)
  • Hang Suea Sakon Nakhon TT1 (HSSNTT1)
  • Kd (KD)
  • Kd_kt (KDKT)
  • Krerng Ka Via (KKV)
  • Purple Duck (PD)
  • Skunk (Auto) (SKA)
  • Sour Diesel (Auto) (SDA)
  • Tanaosri Kan Daeng RD1 (TKDRD1)
  • Tanaosri Kan Kaw WA1 (TKKWA1)
  • Thaistick Foi Thong (TFT)

The image counts per variety was variable, ranging from 49 to 554 images.

Original dataset provided by Chumchu & Patil. Source: Islam et al., 2024


High-resolution images of five different cannabis seed types, each with dimensions of 3024 × 4032 pixels, capturing fine details at 72 dpi resolution. Source: Islam et al., 2024

In the figure above: The seeds, ranging from 2 to 5 mm in size, include (a) AK47, (b) Gelato, (c) Gorilla Purple, (d) KDKT, and (e) Sour Diesel Auto.


Example of ground truth bounding boxes for cannabis seeds. Source: Islam et al., 2024

In the figure above: the high-resolution images (3024 × 4032 pixels, 72 dpi) display cannabis seeds with bounding boxes annotated for object detection. The precise annotations facilitate the training and evaluation of detection models, capturing seeds typically ranging from 2 to 5 mm in size.


2. Model Architectures

The study compared two prominent deep learning models for object detection: RetinaNet (a one-stage detector) and Faster R-CNN (a two-stage detector).

  1. Each model was trained using different backbone architectures: ResNet50, ResNet101, and ResNeXt101.
  2. RetinaNet with a ResNet101 backbone achieved the highest strict mean average precision (mAP) of 0.9458 at an IoU threshold of 0.5 to 0.95, while Faster R-CNN with a ResNet50 backbone had the highest mAP of 0.9428 at a relaxed 0.5 IoU threshold.
  3. The ResNeXt101 backbone, though more complex, slightly underperformed compared to ResNet-based models in most metrics.


3. Performance Metrics

Inference Speed: The RetinaNet models processed around 14.5–16.1 frames per second (FPS), while the Faster R-CNN with a ResNeXt101 backbone achieved the fastest processing speed of 17.5 FPS.

Per-Class Performance: The models showed varying performance across the 17 cannabis seed varieties, with certain models excelling in specific classes, e.g., RetinaNet was more accurate for complex seeds like 'AK47', 'Gorilla Purple', and 'Sour Diesel Auto'.


Qualitative results of RetinaNet models with different backbones on seed classification and localization tasks. Source: Islam et al., 2024

In the figure above: Top row: KKV seeds. Bottom row: SDA seeds. From left to right: ground truth, predictions from RetinaNet with ResNet50 backbone, ResNet101 backbone, and ResNeXt101 backbone. KKV seeds are shown in orange, and SDA seeds are shown in red. The ResNet101 backbone demonstrates superior performance across both classes.


Qualitative comparison of Faster R-CNN models with ResNet50, ResNet101, and ResNeXt101 backbones on BBA and SKA seed classification. Source: Islam et al., 2024

In the figure above: The models’ predictions are shown along with the ground truth labels. BBA seeds are shown in blue, and SKA seeds are shown in red.


4. Data Augmentation

Data augmentation techniques, such as random horizontal/vertical flips, colour adjustments, and blur operations, were applied to improve the model's ability to generalize to unseen data, which was crucial for the training process.

5. Experimental Setup

Both RetinaNet and Faster R-CNN were trained for 100 epochs using the stochastic gradient descent (SGD) optimizer. Learning rates were set at 0.02 for Faster R-CNN and 0.01 for RetinaNet.

Different loss functions were applied to enhance the training, with RetinaNet using Focal Loss and L1 loss for regression, while Faster R-CNN used cross-entropy and IoU loss for classification and bounding box regression.

Quantity of images and instances per seed type in the training, validation, and testing datasets. Source: Islam et al., 2024

6. Comparison with Previous Work

This study extended the authors’ previous work, which focused solely on Faster R-CNN with a ResNet50 backbone, by adding RetinaNet and additional backbone architectures, offering a more comprehensive evaluation of state-of-the-art methods.

RetinaNet improved upon the previous mAP scores and added deeper insights into performance-speed trade-offs, making it more suitable for real-world cannabis seed detection applications.


Performance Comparison of RetinaNet and Faster R-CNN models. Source: Islam et al., 2024

Citation

Islam, T.; Sarker, T.T.; Ahmed, K.R.; Lakhssassi, N. Detection and Classification of Cannabis Seeds Using RetinaNet and Faster R-CNN. Seeds 2024, 3, 456-478. https://doi.org/10.3390/seeds3030031


What's on

If you'd like to receive the regular 'AI in Agriculture' newsletter in your inbox, simply add your email to my mailing list.

Join over 9,100 readers who enjoy weekly updates on AI advancements in agriculture!


Get the 'AI in Agriculture' newsletter delivered straight to your inbox! Simply click the image above and enter your email to join my mailing list
Get the 'AI in Agriculture' newsletter delivered straight to your inbox! Simply click the image above and enter your email to join my mailing list

AI for Cannabis Phenotyping and Quality Assurance

Free mobile application Petiole Pro brings AI to plant phenotyping and quality assurance of cannabis crops
To get more information about crop phenotyping capabilities with mobile - ask Petiole Pro
Taminul Islam

Research Assistant @SIU | PhD Student | Computer Vision

1 周

Thank you Maryna Kuzmenko, Ph.D ???? for featuring our work.

Matt Cummins

Helping Healthtech and Life Sciences SaaS companies to build World-Class sales teams! Let's connect! ?? ???? Ex-sales leader, now sales headhunter and GTM team builder. Family Law Advocate

1 个月

As somebody who was in medical cannabis farming for many years I wonder how this technology helps?

Max Pavan

Business Development / Agtech / Sustainable Agriculture Irrigation /Vertical Farming / Plant Breeding / Sales / Networker

5 个月

Always Informative!

Oleksandr Khyzhniak ????

Strategy & Leadership | AI & Digital Transformation | PMP | Product Management | Venture Investments | Military Veteran

5 个月

Great analysis! Thank you! I will be conducting my field experiments next season:-)

Asmae El-Ghezzaz

Data scientist | AI & ML engineer | EdTech | AgriTech | Google WTM Ambassador | Global Ambassador at WomenTechNetwork

5 个月

Very Useful!

要查看或添加评论,请登录

Maryna Kuzmenko的更多文章