Skip to content

Instantly share code, notes, and snippets.

@nfsrules
Last active April 19, 2018 13:00
Show Gist options
  • Save nfsrules/0ab0fb6bc732431aac12bcf6e60e5f46 to your computer and use it in GitHub Desktop.
Save nfsrules/0ab0fb6bc732431aac12bcf6e60e5f46 to your computer and use it in GitHub Desktop.
Extract relevant activations from a feature map
# 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