Update README.md
Browse files
README.md
CHANGED
@@ -58,29 +58,29 @@ pip install tensorflow pillow matplotlib numpy
|
|
58 |
|
59 |
To load and use the model for predictions:
|
60 |
|
61 |
-
|
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
|
@@ -89,13 +89,13 @@ The integrated *Grad-CAM* functionality allows interpretation of the model's pre
|
|
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
|
|
|
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
|
|
|
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
|