heuzef ca278dc8ef | 2 days ago | |
---|---|---|
.. | ||
Base_JarviSpore.ipynb | 2 days ago | |
Jarvispore.py | 2 days ago | |
README.md | 2 days ago | |
Stropharia_ambigua.jpg | 2 days ago | |
correction_Base_JarviSpore.ipynb | 2 days ago |
This repository contains JarviSpore, a mushroom image classification model trained on a multi-class dataset with 23 different types of mushrooms. Developed from scratch with TensorFlow and Keras, this model aims to provide accurate mushroom identification using advanced deep learning techniques, including Grad-CAM for interpreting predictions. This project explores the performance of from-scratch models compared to transfer learning.
The model was trained using a structured dataset directory with data split as follows:
train
: Balanced training datasetvalidation
: Validation set to monitor performancetest
: Test set to evaluate final accuracyMain training hyperparameters include:
Training was tracked and logged via MLflow, including accuracy and loss curves, as well as the best model weights saved automatically.
Ensure the following libraries are installed:
pip install tensorflow pillow matplotlib numpy
To load and use the model for predictions:
import tensorflow as tf
from PIL import Image
import numpy as np
# Load the model
model = tf.keras.models.load_model("path_to_model.h5")
# Prepare an image for prediction
def prepare_image(image_path):
img = Image.open(image_path).convert("RGB")
img = img.resize((224, 224))
img_array = tf.keras.preprocessing.image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
return img_array
# Prediction
image_path = "path_to_image.jpg"
img_array = prepare_image(image_path)
predictions = model.predict(img_array)
predicted_class = np.argmax(predictions[0])
print(f"Predicted Class: {predicted_class}")
The integrated Grad-CAM functionality allows interpretation of the model’s predictions. To use it, select an image and apply the Grad-CAM function to display the heatmap overlaid on the original image, highlighting areas influencing the model.
Grad-CAM example usage:
# Example usage of the make_gradcam_heatmap function
heatmap = make_gradcam_heatmap(img_array, model, last_conv_layer_name="last_conv_layer_name")
# Superimpose the heatmap on the original image
superimposed_img = superimpose_heatmap(Image.open(image_path), heatmap)
superimposed_img.show()
The model was evaluated on the test set with an average accuracy above random chance, showing promising results for a first from-scratch version.
Contributions to improve accuracy or add new features (e.g., other visualization techniques or advanced optimization) are welcome. Please submit a pull request with relevant modifications.
This model is licensed under a controlled license: please refer to the LICENSE
file for details. You may use this model for personal projects, but any modifications or redistribution must be approved.