lukemelas / deep-spectral-segmentation

[CVPR 2022] Deep Spectral Methods: A Surprisingly Strong Baseline for Unsupervised Semantic Segmentation and Localization
227 stars 41 forks source link

semantic-segmentation produces black images #12

Closed senecobis closed 1 year ago

senecobis commented 1 year ago

Hi after running, extract_features, extract_eigs, extract_single_region_segmentations and extract_crf_segmentations. I get a single_region_segmentation that has some segmentation inside but extract_crf_segmentations produces (I guess it is a simple upscaling) black images.

Chanfeechen commented 1 year ago

@senecobis I encountered the same problem. It turns out to be a minor bug in their code. Try adding the following right after line 695 in file extract\extract.py:

#BUG: segmap_crf is a binary image, but it is saved as a color image
#quick fix: check if max value is 1, if so, multiply by 255
if np.max(segmap_crf) == 1:
    segmap_crf = segmap_crf * 255

It works in my case. @lukemelas @99991 , similar bugs exist in function extract_multi_region_segmentations.

alexaatm commented 1 year ago

@Chanfeechen Hello! I encountered the same problem with semantic segmnettaions. I added 2 lines

    if np.max(segmap) == 1:
        segmap = segmap * 255

in function _extract_multi_region_segmentations right before the call to Image.fromarray(segmap).convert('L').save(output_file) , as well as similar code

        if np.max(semantic_segmap) == 1:
            semantic_segmap = semantic_segmap * 255

in function extract_semantic_segmentations before calling semantic_segmap = np.vectorize(semantic_map.__getitem__)(segmap) (without these there was an error when running vectorize.)

But my segmentations are still black.

Additional info:

Do you have any ideas, what else could be wrong?

chandagrover commented 1 year ago

@Chanfeechen Hello! I encountered the same problem with semantic segmnettaions. I added 2 lines

    if np.max(segmap) == 1:
        segmap = segmap * 255

in function _extract_multi_region_segmentations right before the call to Image.fromarray(segmap).convert('L').save(output_file) , as well as similar code

        if np.max(semantic_segmap) == 1:
            semantic_segmap = semantic_segmap * 255

in function extract_semantic_segmentations before calling semantic_segmap = np.vectorize(semantic_map.__getitem__)(segmap) (without these there was an error when running vectorize.)

But my segmentations are still black.

Additional info:

  • running the code on the data folder which includes 40 samples from Pascal voc 2012 (for testing purposes and speed considerations).
  • N_SEG set to 15 (parameter non_adaptive_num_segments in extract_multi_region_segmentations ). Even though later weirdly the clustering is done for 20 clusters in extract_bbox_clusters
  • parameters are:
MODEL="dino_vits16"
MATRIX="laplacian"
DOWNSAMPLE=16
N_SEG=15
N_ERODE=2
N_DILATE=5

Do you have any ideas, what else could be wrong?

Hi,

I am also getting black images for semantic segmentation. How can I fix it?

chandagrover commented 1 year ago

KIndly reply. I tried a lot. I am getting black images of the semantic segmentation code. Please help.

alexaatm commented 1 year ago

@chandagrover Hi, sorry for a late reply - did not have this repo on radar! As for semantic segmentations being black, the issue was that they are label maps, that is, they have lables 1..K, where K is your number of classes, and not the intensities 0..255 as pixel values - so the values are very low, that is why they seem black. If you inspect the values of your segmaps, they shoudl produce smth like a matrix full of 0s with some non zero pixels which correspond to your class labels...

To save them in a way to see them, you could use image=Image.fromarray(np.uint8(segmap * 255)).convert('L') instead of Image.fromarray(segmap).convert('L') in corresponding functions (like mulri-region-segmentations or crf-segmentations etc...).

Hope this helps!

lukemelas commented 1 year ago

Thanks for helping out, alexaatm!

alexaatm commented 1 year ago

@lukemelas glad to help!!