PS3-4K-SigLIP2
307
1
1 language
—
by
nvidia
Image Model
OTHER
2503.19903B params
New
307 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
5596GB+ RAM
Mobile
Laptop
Server
Quick Summary
AI model with specialized capabilities.
Device Compatibility
Mobile
4-6GB RAM
Laptop
16GB RAM
Server
GPU
Minimum Recommended
2332GB+ RAM
Code Examples
Inference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchInference:bash
pip install ps3-torchbash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .bash
cd PS3
pip install -e .install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")install cv2, matplotlib, scipy for visualization purposepythonpytorch
############## Helper functions for visiualization ##############
# install cv2, matplotlib, scipy for visualization purpose
os.system("pip install opencv-python matplotlib scipy")
from torchvision import transforms
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
def create_heatmap_overlay(image, heatmap, alpha=0.4, colormap=plt.cm.jet, sigma=10.0):
if len(image.shape) == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
smoothed_heatmap = gaussian_filter(heatmap.astype(np.float32), sigma=sigma)
smoothed_heatmap = (smoothed_heatmap - smoothed_heatmap.min()) / \
(smoothed_heatmap.max() - smoothed_heatmap.min())
colored_heatmap = (colormap(smoothed_heatmap) * 255).astype(np.uint8)
if colored_heatmap.shape[-1] == 4:
colored_heatmap = colored_heatmap[:, :, :3]
overlay = cv2.addWeighted(image, 1 - alpha, colored_heatmap, alpha, 0)
return Image.fromarray(overlay)
def save_visualization(selection_probs, image, output_dir):
os.makedirs(output_dir, exist_ok=True)
resize_transform = transforms.Resize(image.size[::-1])
for i, prob in enumerate(selection_probs):
prob = (prob - prob.min()) / (prob.max() - prob.min() + 1e-6)
prob = resize_transform(prob)
prob = prob.squeeze(0).detach().cpu().numpy()
# overlay the selection probability map on the original image
overlay = create_heatmap_overlay(np.array(image), prob)
overlay.save(os.path.join(output_dir, f"selection_prob_scale_{i}.png"))
image.save(os.path.join(output_dir, f"image.png"))
#################### End of helper functions ####################
selection_probs = outs.selection_probs
print([p.shape for p in selection_probs]) # [(1, 54, 54), (1, 108, 108), (1, 270, 270)]
save_visualization(selection_probs, image, "save_path/bottom_up_selection_probs")Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.