-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save activation images for each layer
- Loading branch information
Showing
7 changed files
with
223 additions
and
227 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Activations | ||
|
||
Feature map activations are stored in this directory. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import math | ||
import numpy as np | ||
import cv2 as cv | ||
import matplotlib | ||
matplotlib.use('Agg') # Workaround to save images when running over ssh sessions | ||
import matplotlib.pyplot as plt | ||
import matplotlib.image as mpimg | ||
|
||
|
||
def tile_ims(filename, directory): | ||
"""Load all images in the given directory and tile them into one.""" | ||
ims = [mpimg.imread(os.path.join(directory, f)) for f in | ||
sorted(os.listdir(directory))] | ||
save_ims(filename, np.array(ims)) | ||
|
||
|
||
def save_im(filename, im): | ||
# h, w, c = im.shape | ||
cv.imwrite(filename, im) | ||
|
||
|
||
def save_ims(filename, ims): | ||
n, h, w, c = ims.shape | ||
|
||
# Plot the images on a grid | ||
rows = int(math.ceil(math.sqrt(n))) | ||
cols = int(round(math.sqrt(n))) | ||
|
||
# Each subplot should have the same resolutions as the image dimensions | ||
|
||
# TODO: Consider proper heights and widths for the subplots | ||
h = 64 | ||
w = 64 | ||
|
||
fig, axes = plt.subplots(rows, cols, figsize=(h, w)) | ||
fig.subplots_adjust(hspace=0, wspace=0) | ||
|
||
for i, ax in enumerate(axes.flat): | ||
ax.axis('off') # Hide x, y axes completely | ||
if i < n: | ||
ax.imshow(ims[i]) | ||
|
||
plt.savefig(filename, bbox_inches='tight') | ||
plt.clf() |
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
Oops, something went wrong.