Last active
April 19, 2018 13:00
-
-
Save nfsrules/0ab0fb6bc732431aac12bcf6e60e5f46 to your computer and use it in GitHub Desktop.
Extract relevant activations from a feature map
This file contains 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
# Get numpy array from matplotlib figure | |
target_map = get_figure(target_map, cmap='inferno').astype('uint8') | |
# Crop unnecessary regions from canvas | |
target_map = crop(target_map,9,63,33,232) | |
# Resize to original image size | |
target_map = cv2.resize(target_map,(1800,480), interpolation = cv2.INTER_CUBIC) | |
# Create a binary mask. You may want to change the binary threshold | |
img2gray = cv2.cvtColor(target_map,cv2.COLOR_BGR2GRAY) | |
ret, mask = cv2.threshold(img2gray, 80, 255, cv2.THRESH_BINARY) | |
# Apply mask to activation map | |
dst_map = cv2.bitwise_and(target_map, target_map, mask=mask) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment