Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -207,7 +207,6 @@ def generate_adversarial(input_image, orig_pred, epsilon=20/255, steps=500):
|
|
| 207 |
# return output
|
| 208 |
return output
|
| 209 |
|
| 210 |
-
# Prediction function
|
| 211 |
def predict(image, brightness, contrast, hue, overlay_image, alpha, adversarial_switch):
|
| 212 |
"""Main prediction function"""
|
| 213 |
if image is None:
|
|
@@ -217,7 +216,7 @@ def predict(image, brightness, contrast, hue, overlay_image, alpha, adversarial_
|
|
| 217 |
|
| 218 |
# Apply preprocessing
|
| 219 |
processed = apply_filters(image, brightness, contrast, hue)
|
| 220 |
-
final_image = superimpose_images(processed, overlay_image, alpha)
|
| 221 |
|
| 222 |
# Generate adversarial if enabled
|
| 223 |
if adversarial_switch:
|
|
@@ -241,13 +240,13 @@ def predict(image, brightness, contrast, hue, overlay_image, alpha, adversarial_
|
|
| 241 |
output = model(model_input)
|
| 242 |
probs = F.softmax(output, dim=1).cpu().numpy()[0]
|
| 243 |
|
| 244 |
-
# Generate Grad-CAM
|
| 245 |
heatmap, _ = gradcam.generate(model_input)
|
| 246 |
final_np = np.array(final_display)
|
| 247 |
heatmap = cv2.resize(heatmap, final_np.shape[:2][::-1])
|
| 248 |
heatmap = cv2.applyColorMap(np.uint8(255 * heatmap), cv2.COLORMAP_JET)
|
| 249 |
superimposed = cv2.addWeighted(cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB), 0.5, final_np, 0.5, 0)
|
| 250 |
-
|
| 251 |
# Create plot
|
| 252 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 253 |
top5_idx = np.argsort(probs)[-5:][::-1]
|
|
|
|
| 207 |
# return output
|
| 208 |
return output
|
| 209 |
|
|
|
|
| 210 |
def predict(image, brightness, contrast, hue, overlay_image, alpha, adversarial_switch):
|
| 211 |
"""Main prediction function"""
|
| 212 |
if image is None:
|
|
|
|
| 216 |
|
| 217 |
# Apply preprocessing
|
| 218 |
processed = apply_filters(image, brightness, contrast, hue)
|
| 219 |
+
final_image = superimpose_images(processed, overlay_image, alpha) # Overlay the image properly
|
| 220 |
|
| 221 |
# Generate adversarial if enabled
|
| 222 |
if adversarial_switch:
|
|
|
|
| 240 |
output = model(model_input)
|
| 241 |
probs = F.softmax(output, dim=1).cpu().numpy()[0]
|
| 242 |
|
| 243 |
+
# Generate Grad-CAM on the properly transformed image with overlay
|
| 244 |
heatmap, _ = gradcam.generate(model_input)
|
| 245 |
final_np = np.array(final_display)
|
| 246 |
heatmap = cv2.resize(heatmap, final_np.shape[:2][::-1])
|
| 247 |
heatmap = cv2.applyColorMap(np.uint8(255 * heatmap), cv2.COLORMAP_JET)
|
| 248 |
superimposed = cv2.addWeighted(cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB), 0.5, final_np, 0.5, 0)
|
| 249 |
+
|
| 250 |
# Create plot
|
| 251 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 252 |
top5_idx = np.argsort(probs)[-5:][::-1]
|