mhamilton723 / STEGO

Unsupervised Semantic Segmentation by Distilling Feature Correspondences
MIT License
711 stars 142 forks source link

Show only a specific cluster in resulted image #59

Closed ha-daiy closed 1 year ago

ha-daiy commented 1 year ago

Hi, After using provided google Colab demo, I just wanted to know if this could be possible to show only a desired cluster on the final resulted image?(Not all the detected ones.) I saw Issue 18 but did not understand how to this task. As an example this is an image I tried to segment: 2022_GOOD-4 As you can see there are almost 4 clusters on the image for each method. How could I only segment/plot the animal(s) cluster on the final image for each method? Thanks

mhamilton723 commented 1 year ago

You can edit the plotting code with a quick predicate which checks whether yours preds are equal to the class you care about. Heres a quick idea (you might nd to edit this a bit to get it to work)

import matplotlib.pyplot as plt
from utils import unnorm, remove_axes
fig, ax = plt.subplots(1,3, figsize=(5*3,5))
ax[0].imshow(unnorm(img)[0].permute(1,2,0).cpu())
ax[0].set_title("Image")
ax[1].imshow(cluster_pred == MY_CLUSTER_CLASS)
ax[1].set_title("Cluster Predictions")
ax[2].imshow(linear_pred == MY_LINEAR_CLASS)
ax[2].set_title("Linear Probe Predictions")
remove_axes(ax)