What's Fresh & What's Rotten is our way to solve problem about fruits classification whether it is rotten or it is fresh (safely can be eaten) using Deep Learning. We do simple CNN to expect some basic performance. Then we improved the model by adding Transfer Learning with VGG-16 and ResNet50 as our baseline model.
Used the Fruit fresh and rotten for classification kaggle dataset. The dataset contains 13599 images of apple, banana and orange divided into fresh and rotten each.
Dataset | Directories | Files |
---|---|---|
Train | freshapples | 1693 |
freshbanana | 1581 | |
freshoranges | 1466 | |
rottenapples | 2342 | |
rottenbanana | 2224 | |
rottenoranges | 1595 | |
Test | freshapples | 395 |
freshbanana | 381 | |
freshoranges | 388 | |
rottenapples | 601 | |
rottenbanana | 530 | |
rottenoranges | 403 |
- Convolutional Neural Network:
- ResNet50V2
- VGG16
- Sequential Models
- Sklearn
- Tensorflow
- Keras
- OpenCV
Process how the project was done:
- Getting the information of the dataset.
- Randomly choosing the fruit image to get the size of the image and also its preview.
- Resizing the images to size of (150,150) and scaling both the train and test datasets.
- Used sequential model (3 layer convolutional layer), ResNet50 model and VGG-16 using transfer learning.
- Plot the accuracy and loss metric.
- Evaluate the accuracy of the model.
- Predict the image from test dataset.
Model | Total Parameters | Loss | Accuracy | Optimizer | Loss metric |
---|---|---|---|---|---|
Sequential 3 layer | 9,497,126 | 0.0960 | 96.96% | RMSprop | Categorical CrossEntropy |
ResNet50V2 | 23,696,326 | 0.0259 | 97.41% | Adam | Binary CrossEntropy |
VGG16 | 14,747,910 | 0.108 | 91.4% | Adam | Binary CrossEntropy |
from keras.preprocessing.image import img_to_array names = [fresh_apples_test_dir, fresh_banana_test_dir, fresh_oranges_test_dir, rotten_apples_test_dir, rotten_banana_test_dir, rotten_oranges_test_dir ] name_rand = random.choice(names) filename = os.listdir(name_rand) sample = random.choice(filename) fn = os.path.join(name_rand,sample) print(fn) img = load_img(fn, target_size=(150, 150)) plt.imshow(img) x = img_to_array(img) x = np.expand_dims(x, axis=0) images = np.vstack([x]) classes = model.predict(images, batch_size=10) print(classes) prediction = '' if classes[0][0]==1: prediction = 'fresh apple' elif classes[0][1]==1: prediction = 'fresh banana' elif classes[0][2]==1: prediction = 'fresh orange' elif classes[0][3]==1: prediction = 'rotten apple' elif classes[0][4]==1: prediction = 'rotten banana' elif classes[0][5]==1: prediction = 'rotten orange' print(prediction)
To make a website integrated with IoT devices to detect whether fruit is rotten or not in real-time.
I have taken references from: