Tomato is one of the most popular and widely grown vegetable crops in the world. It belongs to the family Solanaceae. It is one of the very perishable fruit and it changes continuously after harvesting. Depending on the humidity and temperature it ripens very soon, ultimately resulted in poor quality as the fruit become soft and unacceptable. Color in tomato is the most important external characteristic to assess ripeness and post harvest life, and is a major factor in the consumer’s purchase decision. Degree of ripening is usually estimated by color charts. There are six ripening stages reflecting human ability to differentiate ripeness: green, 100% green; breaker, a noticeable break in color with lesser than 10% of other than green color; turning, between 10 and 30% of surface, in the aggregate, of red(ish) color; pink, between 30 and 60% of red(ish) color; light red, between 60 and 90% and red, more than 90% red. We have taken 3 stages and classified them into grades.
We have used Particle Argon for computations and Adafruit TCS34725 sensor to capture the colors.
The data for training was collected from the sensor using a simple code.
#include <Wire.h>
#include "Adafruit_TCS34725.h"
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
void setup(void) {
Serial.begin(9600);
if (tcs.begin())
{
Serial.println("Found sensor");
}
else
{
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
}
void loop(void)
{
uint16_t r, g, b, c;
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.println(" ");
}
This code prints data in serial monitor. The Red, Green and Blue values are copied to an excel sheet and is saved in CSV format.
The data is next uploaded in a new google colaboratory file which runs TensorFlow.
Google ColaboratoryTensorFlow is installed by:
!apt-get -qq install xxd
!pip install pandas numpy matplotlib
%tensorflow_version 2.x
!pip install tensorflow
The data is uploaded and visualized in pixels:
The model is built and Trained
Running the prediction :
The data is then converted into TensorFlow Lite model and is embedded into.h file.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
open("gesture_model.tflite", "wb").write(tflite_model)
import os
basic_model_size = os.path.getsize("gesture_model.tflite")
print("Model is %d bytes" % basic_model_size)
!echo "const unsigned char model[] = {" > /content/model.h
!cat gesture_model.tflite | xxd -i >> /content/model.h
!echo "};" >> /content/model.h
import os
model_h_size = os.path.getsize("model.h")
print(f"Header file, model.h, is {model_h_size:,} bytes.")
print("\nOpen the side panel (refresh if needed). Double click model.h to download the file.")
Running ML in ArgonThe model.h file is then used with our code to run the prediction. We had successful output and the classification was done right.
That's it! Feel free to contact us for more information. Thank you.
Comments