Iris314/Food_tomatoes_dataset
Viewer โข Updated โข 539 โข 6 โข 1
How to use kaitongg/best_tomato_model with Keras:
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://kaitongg/best_tomato_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).
The model architecture was determined using Keras Tuner's Hyperband algorithm. Based on the previous tuning results, the best hyperparameters found were:
conv_blocks: 2filters_0: 32dense_units: 64dropout: 0.1lr: 0.001filters_1: 16The model consists of:
augmented split was used for training, and the original split was used for validation.Based on the evaluation on the validation set, the model achieved the following performance:
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}")