Created
November 15, 2019 07:17
-
-
Save Siyeong-Lee/8789d56b87de94cc7936c6ad49c21535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| params = list(net.parameters()) | |
| # get only weight from last layer(linear) | |
| weight_softmax = np.squeeze(params[-2].cpu().data.numpy()) | |
| def returnCAM(feature_conv, weight_softmax, class_idx): | |
| size_upsample = (128, 128) | |
| bz, nc, h, w = feature_conv.shape | |
| output_cam = [] | |
| for idx in class_idx: | |
| cam = weight_softmax[class_idx].dot(feature_conv.reshape( (nc, h*w))) | |
| cam = cam.reshape(h, w) | |
| cam = cam - np.min(cam) | |
| cam_img = cam/np.max(cam) | |
| cam_img = np.uint8(255 * cam_img) | |
| output_cam.append(cv2.resize(cam_img, size_upsample)) | |
| return output_cam |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment