Update README.md
Browse files
README.md
CHANGED
|
@@ -34,9 +34,9 @@ This repository contains **JarviSpore**, a mushroom image classification model t
|
|
| 34 |
## Model Training
|
| 35 |
|
| 36 |
The model was trained using a structured dataset directory with data split as follows:
|
| 37 |
-
-
|
| 38 |
-
-
|
| 39 |
-
-
|
| 40 |
|
| 41 |
Main training hyperparameters include:
|
| 42 |
- **Batch Size**: 32
|
|
@@ -50,5 +50,62 @@ Training was tracked and logged via MLflow, including accuracy and loss curves,
|
|
| 50 |
### Prerequisites
|
| 51 |
|
| 52 |
Ensure the following libraries are installed:
|
| 53 |
-
|
| 54 |
pip install tensorflow pillow matplotlib numpy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
## Model Training
|
| 35 |
|
| 36 |
The model was trained using a structured dataset directory with data split as follows:
|
| 37 |
+
- train: Balanced training dataset
|
| 38 |
+
- validation: Validation set to monitor performance
|
| 39 |
+
- test: Test set to evaluate final accuracy
|
| 40 |
|
| 41 |
Main training hyperparameters include:
|
| 42 |
- **Batch Size**: 32
|
|
|
|
| 50 |
### Prerequisites
|
| 51 |
|
| 52 |
Ensure the following libraries are installed:
|
| 53 |
+
bash
|
| 54 |
pip install tensorflow pillow matplotlib numpy
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
### Loading the Model
|
| 58 |
+
|
| 59 |
+
To load and use the model for predictions:
|
| 60 |
+
|
| 61 |
+
python
|
| 62 |
+
import tensorflow as tf
|
| 63 |
+
from PIL import Image
|
| 64 |
+
import numpy as np
|
| 65 |
+
|
| 66 |
+
# Load the model
|
| 67 |
+
model = tf.keras.models.load_model("path_to_model.h5")
|
| 68 |
+
|
| 69 |
+
# Prepare an image for prediction
|
| 70 |
+
def prepare_image(image_path):
|
| 71 |
+
img = Image.open(image_path).convert("RGB")
|
| 72 |
+
img = img.resize((224, 224))
|
| 73 |
+
img_array = tf.keras.preprocessing.image.img_to_array(img)
|
| 74 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 75 |
+
return img_array
|
| 76 |
+
|
| 77 |
+
# Prediction
|
| 78 |
+
image_path = "path_to_image.jpg"
|
| 79 |
+
img_array = prepare_image(image_path)
|
| 80 |
+
predictions = model.predict(img_array)
|
| 81 |
+
predicted_class = np.argmax(predictions[0])
|
| 82 |
+
|
| 83 |
+
print(f"Predicted Class: {predicted_class}")
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
### Grad-CAM Visualization
|
| 87 |
+
|
| 88 |
+
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.
|
| 89 |
+
|
| 90 |
+
Grad-CAM example usage:
|
| 91 |
+
|
| 92 |
+
python
|
| 93 |
+
# Example usage of the make_gradcam_heatmap function
|
| 94 |
+
heatmap = make_gradcam_heatmap(img_array, model, last_conv_layer_name="last_conv_layer_name")
|
| 95 |
+
|
| 96 |
+
# Superimpose the heatmap on the original image
|
| 97 |
+
superimposed_img = superimpose_heatmap(Image.open(image_path), heatmap)
|
| 98 |
+
superimposed_img.show()
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
## Evaluation
|
| 102 |
+
|
| 103 |
+
The model was evaluated on the test set with an average accuracy above random chance, showing promising results for a first from-scratch version.
|
| 104 |
+
|
| 105 |
+
## Contributing
|
| 106 |
+
|
| 107 |
+
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.
|
| 108 |
+
|
| 109 |
+
## License
|
| 110 |
+
|
| 111 |
+
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.
|