YudeWang / SEAM

Self-supervised Equivariant Attention Mechanism for Weakly Supervised Semantic Segmentation, CVPR 2020 (Oral)
MIT License
542 stars 97 forks source link

crf code should be changed #45

Closed Elaineok closed 1 year ago

Elaineok commented 1 year ago
    def _crf_with_alpha(cam_dict, alpha):
        v = np.array(list(cam_dict.values()))
        bg_score = np.power(1 - np.max(v, axis=0, keepdims=True), alpha)
        bgcam_score = np.concatenate((bg_score, v), axis=0)
        crf_score = imutils.crf_inference(orig_img, bgcam_score, labels=bgcam_score.shape[0])
        pred_map = crf_score.argmax(0).astype(np.uint8)
        keys = np.array(list(cam_dict.keys()))+1
        keys = np.pad(keys, (1, 0), mode='constant')
        pred_map = keys[pred_map]
        return pred_map

    for t in crf_alpha:
        crf = _crf_with_alpha(cam_dict, t)
        folder = args.out_crf + ('_%.1f' % t)
        if not os.path.exists(folder):
            os.makedirs(folder)
        import imageio
        imageio.imsave(os.path.join(folder, "%s.png" % img_name), crf.astype(np.uint8))

    print(iter)

`