Tomato Binary Classification Model

This model is a convolutional neural network trained to classify images of tomatoes into two categories (presumably ripe and unripe, based on the dataset name and binary classification setup).

Model Architecture

The model architecture was determined using Keras Tuner's Hyperband algorithm. Based on the previous tuning results, the best hyperparameters found were:

  • conv_blocks: 2
  • filters_0: 32
  • dense_units: 64
  • dropout: 0.1
  • lr: 0.001
  • filters_1: 16

The model consists of:

  • Data augmentation layers (RandomFlip, RandomRotation, RandomZoom) applied during training.
  • Two convolutional blocks:
    • The first block has 32 filters, a 3x3 kernel, ReLU activation, and MaxPooling.
    • The second block has 16 filters, a 3x3 kernel, ReLU activation, and MaxPooling.
  • A Flatten layer.
  • A dense layer with 64 units and ReLU activation.
  • A Dropout layer with a rate of 0.1.
  • An output layer with a single unit and a sigmoid activation function for binary classification.

Training

  • Dataset: Iris314/Food_tomatoes_dataset. The augmented split was used for training, and the original split was used for validation.
  • Input Resolution: Images are resized to 128x128 pixels.
  • Preprocessing: Images are converted to RGB and pixel values are scaled to the range [0, 1].
  • Optimizer: Adam with a learning rate of 0.001 (based on the best hyperparameters).
  • Loss Function: Binary Crossentropy.
  • Metrics: Accuracy was used as the evaluation metric.
  • Early Stopping: Training was stopped early if the validation loss did not improve for 3 consecutive epochs. The model was trained for a maximum of 15 epochs.

Performance

Based on the evaluation on the validation set, the model achieved the following performance:

  • Accuracy: 1.00
  • Loss: 0.0079

Classification Report:

import tensorflow as tf
from PIL import Image
import numpy as np

#Load the model
model = tf.keras.models.load_model('best_tomato_model.keras')

#Load and preprocess an image
img_path = 'path/to/your/image.jpg' # Replace with your image path
img = Image.open(img_path).convert('RGB').resize((128, 128))
img_array = np.array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension

#Make a prediction
prediction = model.predict(img_array)

#Interpret the prediction
predicted_class = int(prediction > 0.5)

print(f"Prediction: {prediction[0][0]:.4f}")
print(f"Predicted class: {predicted_class}")
Downloads last month
31
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train kaitongg/best_tomato_model

Spaces using kaitongg/best_tomato_model 2