Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
|
3 |
import os
|
4 |
import numpy as np
|
@@ -32,7 +32,7 @@ val_data = datagen.flow_from_directory(
|
|
32 |
subset='validation' # Set as validation data
|
33 |
)
|
34 |
|
35 |
-
|
36 |
|
37 |
import tensorflow as tf
|
38 |
from tensorflow.keras.applications import ResNet50
|
@@ -64,7 +64,7 @@ model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']
|
|
64 |
# Model summary
|
65 |
model.summary()
|
66 |
|
67 |
-
|
68 |
|
69 |
# Train the model
|
70 |
history = model.fit(
|
@@ -103,7 +103,7 @@ plt.grid(True)
|
|
103 |
plt.tight_layout()
|
104 |
plt.show()
|
105 |
|
106 |
-
|
107 |
|
108 |
import numpy as np
|
109 |
import tensorflow as tf
|
@@ -166,13 +166,13 @@ heatmap = make_gradcam_heatmap(img_array, model, 'conv5_block3_out') # Replace
|
|
166 |
# Display the original image with the Grad-CAM heatmap overlay
|
167 |
display_gradcam(img_path, heatmap)
|
168 |
|
169 |
-
|
170 |
|
171 |
# Evaluate model on validation data
|
172 |
test_loss, test_acc = model.evaluate(val_data, verbose=2)
|
173 |
print(f'Test Accuracy: {test_acc:.2f}')
|
174 |
|
175 |
-
|
176 |
|
177 |
!pip install gradio
|
178 |
|
|
|
1 |
+
#Data Preprocessing
|
2 |
|
3 |
import os
|
4 |
import numpy as np
|
|
|
32 |
subset='validation' # Set as validation data
|
33 |
)
|
34 |
|
35 |
+
#CNN Model Setup (Transfer Learning)
|
36 |
|
37 |
import tensorflow as tf
|
38 |
from tensorflow.keras.applications import ResNet50
|
|
|
64 |
# Model summary
|
65 |
model.summary()
|
66 |
|
67 |
+
#Training the Model
|
68 |
|
69 |
# Train the model
|
70 |
history = model.fit(
|
|
|
103 |
plt.tight_layout()
|
104 |
plt.show()
|
105 |
|
106 |
+
#Explainable AI Integration (Grad-CAM)
|
107 |
|
108 |
import numpy as np
|
109 |
import tensorflow as tf
|
|
|
166 |
# Display the original image with the Grad-CAM heatmap overlay
|
167 |
display_gradcam(img_path, heatmap)
|
168 |
|
169 |
+
#Evaluation
|
170 |
|
171 |
# Evaluate model on validation data
|
172 |
test_loss, test_acc = model.evaluate(val_data, verbose=2)
|
173 |
print(f'Test Accuracy: {test_acc:.2f}')
|
174 |
|
175 |
+
#Gradio User Interface
|
176 |
|
177 |
!pip install gradio
|
178 |
|