Thai jasmine rice is considered one of the world’s most delicious cultivars of rice. Is there anyway we could identify this type of rice out of others and check their quality?
Our goal is to identify and segment out the Jasmine Rice given in a specific picture and evaluate the overall quality of the rice in that picture.
- Each type of rice is hard to differentiate from each other.
- How do we define the “quality” of rice?
- Are there any datasets available? Is it suitable with the project?
- How can we create and train this model for the best results?
- Clone the repository:
git clone https://github.com/TeaChanathip/Jasmine-Rice-Quality-Rating.git
- Navigate to the project directory:
cd Jasmine-Rice-Quality-Rating - Install dependencies:
Option 1: Using Conda (recommended)
- Create a new conda environment from the
environment.yamlfile:conda env create -f environment.yaml
- Activate the conda environment:
conda activate cv_term_project
- Create a virtual environment
python3 -m venv venv
- Activate the virtual environment:
- On Windows:
venv/Scripts/activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
- Install the dependencies:
pip install -r requirements.txt
- Create a new conda environment from the
- Copy your testing images into
./testfolder - Open and run all
main-application.ipynb - Check running results in
./output/run-{running-timestamp}folder
- Reading the image
- Image should be in
jpgformat
- Image should be in
- Preprocessing the image for segmentation
- Resize all images to
1440x1440
- Resize all images to
- Segmentation Methods
- Use
YoloV8 Segmentationfor first stage mask and predict if each rice is jasmine rice or not. - Then, use
Watershedfor smoothened masking.
- Use
- Classification Methods
- Use
YoloV8 Classificationfor label rice's quality asGood,Moderate,Bad
- Use
- Quality Measurement
- Each rice's "quality score" are computed by 2 factors:
- Ratio of rice's
high/width - Ratio of
#jasmine rice/#total rice
- Ratio of rice's
- Each rice's "quality score" are computed by 2 factors:
- Output
- Overall
- Masked segmentation image
- Overall quality score
- Ratio of jasmine rice
- Per rice
- Rice's image
- Jasmine rice indication
- Quality label
- Overall
And put your image in the test folder like this:
root
|__ test
|__ input1.jpg
|__ input2.jpg
|__ input3.jpg
|__ ...
|__ main-application.ipynb
|__ ...
Each rice was segmented using transfer learning YoloV8 segmentation model. This step also predicts whether each rice is jasmine rice or not.
Since the dataset only have single rice images, we had systhesized a new dataset by using various backgrounds and random original rice images. We also prevented the rice to collide with each other by using image overlapping check.
After the segmentation from the YOLOv8 model, each rice was then segmented by the Watershed algorithm for higher quality masking.
Next, each rice was classified by transfer learning YoloV8 classification model into 3 classes: Good, Moderate, Bad as soft label.
The model was trained with YoloV8 as the base model with 1050 labeled rice images. There are 3 labels: Good, Moderate, Bad.
Adaptive Model Training strategy was also used to inject more unlabeled data into the training process. This results in lesser amount of loss in validation and a more stable model.
Each rice in the image will be scored using 2 factors:
- Ratio of width and height, this is done by:
- Finding the contour of each rice and applying
convexHull. - Finding the maxima of
high/widthby rotating the result from step 1. - Mapping the result from step 2 to score ranging from 0 to 3.
- Finding the contour of each rice and applying
- Quality label of rice, this is done by:
- Choosing the
maximum probabilityof the soft labels from the classification result as the quality label. - Mapping the quality label to score ranging from 0 to 2.
The score were then summed together, giving the final score in the range from
0 to 5.
- Choosing the
Each image will then be scored by:
- Average of all rice's score in the image
- Map ratio of jasmine rice to score from 0 to 5
- Weighted average of 2 scores above in range from
0 to 5
https://www.kaggle.com/datasets/alikhalilit98/rice-image-dataset-for-object-segmentation/data
https://www.kaggle.com/datasets/alikhalilit98/rice-image-dataset-for-object-detection




