Spaces:
Runtime error
Runtime error
Update app.py
Browse files243 unmodified lines2442452462472482492502512522532542552561 unmodified line258259260261262263264243 unmodified linesw, h = image_pil.sizesize = max(w, h)# Resize CAM to match imagecam_resized = np.array(Image.fromarray(cam).resize((size, size), resample=Image.Resampling.BILINEAR))# Normalize CAM to [0, 1]cam_norm = (cam_resized - cam_resized.min()) / (np.ptp(cam_resized) + 1e-8)cam_norm = transforms.CenterCrop((h, w))(cam_norm)# Create heatmap using matplotlib colormapcolormap = cm.get_cmap('jet')1 unmodified linecam_alpha = (cam_norm >= vis_threshold).astype(np.float32) * alpha # Alpha maskcam_rgba = np.dstack((cam_colored, cam_alpha)) # Shape: (H, W, 4)cam_image = Image.fromarray((cam_rgba * 255).astype(np.uint8), mode="RGBA")# Composite over originalcomposite = Image.alpha_composite(image_pil, cam_image)243 unmodified lines2442452462472482492502511 unmodified line253254255256257258259260261262263264265243 unmodified linesw, h = image_pil.sizesize = max(w, h)# Normalize CAM to [0, 1]cam_norm = (cam - cam.min()) / (np.ptp(cam) + 1e-8)# Create heatmap using matplotlib colormapcolormap = cm.get_cmap('jet')1 unmodified linecam_alpha = (cam_norm >= vis_threshold).astype(np.float32) * alpha # Alpha maskcam_rgba = np.dstack((cam_colored, cam_alpha)) # Shape: (H, W, 4)# Resize CAM to match imagecam_resized = np.array(Image.fromarray(cam_rgba).resize((size, size), resample=Image.Resampling.BILINEAR))cam_resized = transforms.CenterCrop((h, w))(torch.tensor(cam_resized)).numpy()cam_image = Image.fromarray((cam_resized * 255).astype(np.uint8), mode="RGBA")# Composite over originalcomposite = Image.alpha_composite(image_pil, cam_image)
app.py+8-7