Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -211,6 +211,9 @@ def predict(image, brightness, contrast, hue, overlay_image, alpha, adversarial_
|
|
211 |
# Apply preprocessing
|
212 |
processed = apply_filters(image, brightness, contrast, hue)
|
213 |
final_image = superimpose_images(processed, overlay_image, alpha)
|
|
|
|
|
|
|
214 |
|
215 |
# Convert to tensor
|
216 |
to_tensor = transforms.Compose([transforms.Resize(32), transforms.ToTensor()])
|
@@ -223,10 +226,10 @@ def predict(image, brightness, contrast, hue, overlay_image, alpha, adversarial_
|
|
223 |
orig_pred = torch.argmax(orig_out).item()
|
224 |
adv_tensor_01 = generate_adversarial(final_image, orig_pred)
|
225 |
final_display = transforms.ToPILImage()(adv_tensor_01.squeeze().cpu().detach())
|
226 |
-
model_input = transform_image(final_display)
|
227 |
else:
|
228 |
final_display = final_image
|
229 |
-
model_input = transform_image(final_image)
|
230 |
|
231 |
# Get predictions
|
232 |
with torch.no_grad():
|
@@ -236,7 +239,7 @@ def predict(image, brightness, contrast, hue, overlay_image, alpha, adversarial_
|
|
236 |
# Generate Grad-CAM
|
237 |
heatmap, _ = gradcam.generate(model_input)
|
238 |
final_np = np.array(final_display)
|
239 |
-
heatmap = cv2.resize(heatmap, final_np.shape[
|
240 |
heatmap = cv2.applyColorMap(np.uint8(255 * heatmap), cv2.COLORMAP_JET)
|
241 |
superimposed = cv2.addWeighted(cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB), 0.5, final_np, 0.5, 0)
|
242 |
|
|
|
211 |
# Apply preprocessing
|
212 |
processed = apply_filters(image, brightness, contrast, hue)
|
213 |
final_image = superimpose_images(processed, overlay_image, alpha)
|
214 |
+
|
215 |
+
# Store the original size
|
216 |
+
original_size = final_image.size
|
217 |
|
218 |
# Convert to tensor
|
219 |
to_tensor = transforms.Compose([transforms.Resize(32), transforms.ToTensor()])
|
|
|
226 |
orig_pred = torch.argmax(orig_out).item()
|
227 |
adv_tensor_01 = generate_adversarial(final_image, orig_pred)
|
228 |
final_display = transforms.ToPILImage()(adv_tensor_01.squeeze().cpu().detach())
|
229 |
+
# model_input = transform_image(final_display)
|
230 |
else:
|
231 |
final_display = final_image
|
232 |
+
# model_input = transform_image(final_image)
|
233 |
|
234 |
# Get predictions
|
235 |
with torch.no_grad():
|
|
|
239 |
# Generate Grad-CAM
|
240 |
heatmap, _ = gradcam.generate(model_input)
|
241 |
final_np = np.array(final_display)
|
242 |
+
heatmap = cv2.resize(heatmap, (final_np.shape[1], final_np.shape[0]))
|
243 |
heatmap = cv2.applyColorMap(np.uint8(255 * heatmap), cv2.COLORMAP_JET)
|
244 |
superimposed = cv2.addWeighted(cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB), 0.5, final_np, 0.5, 0)
|
245 |
|