Skip to content

Commit 209a200

Browse files
committed
Save figure
1 parent 3171e09 commit 209a200

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ UFLDL_Tutorial
33

44
UFLDL Tutorial
55

6-
A python implementation of the exercises on http://ufldl.stanford.edu/wiki/index.php/UFLDL_Tutorial
7-
8-
Including
6+
A python implementation of the exercises on http://ufldl.stanford.edu/wiki/index.php/UFLDL_Tutorial, including
97

108
Sparse Autoencoder
119

sparse_autoencoder/display_network.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import matplotlib.cm as cm
66

77

8-
def display_network(data, cols=-1, opt_normalize=True, opt_graycolor=True):
8+
def display_network(data, cols=-1, opt_normalize=True, opt_graycolor=True, save_figure_path=None):
99
# This function visualizes filters in matrix A. Each row of A is a
1010
# filter. We will reshape each row into a square image and visualizes
1111
# on each cell of the visualization panel.
@@ -68,4 +68,7 @@ def display_network(data, cols=-1, opt_normalize=True, opt_graycolor=True):
6868

6969
plt.axis('off')
7070

71-
plt.show()
71+
if save_figure_path:
72+
plt.savefig(save_figure_path)
73+
74+
plt.show()

sparse_autoencoder/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def train():
100100

101101
# STEP 5: Visualization
102102
w1 = res.x[0: hidden_size*visible_size].reshape((visible_size, hidden_size))
103-
display_network(np.transpose(w1), 5)
103+
display_network(np.transpose(w1), 5, save_figure_path='../data/sparse_autoencoder.png')
104104

105105

106106
if __name__ == "__main__":

0 commit comments

Comments
 (0)