Skip to content

Commit e68c89a

Browse files
visualize features
1 parent 471f7bc commit e68c89a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import numpy as np
2+
import theano
3+
import theano.tensor as T
4+
import matplotlib.pyplot as plt
5+
6+
from sklearn.utils import shuffle
7+
from theano.tensor.shared_randomstreams import RandomStreams
8+
from util import relu, error_rate, getKaggleMNIST, init_weights
9+
from unsupervised import DBN
10+
from rbm import RBM
11+
12+
13+
def main(loadfile=None, savefile=None):
14+
Xtrain, Ytrain, Xtest, Ytest = getKaggleMNIST()
15+
if loadfile:
16+
dbn = DBN([1000, 750, 500, 10]) # AutoEncoder is default
17+
dbn = DBN([1000, 750, 500, 10], UnsupervisedModel=RBM)
18+
dbn.fit(Xtrain, pretrain_epochs=15)
19+
else:
20+
dbn.load(loadfile)
21+
22+
if savefile:
23+
dbn.save(savefile)
24+
25+
# initial weight is D x M
26+
# W = dbn.hidden_layers[0].W.eval()
27+
# for i in xrange(dbn.hidden_layers[0].M):
28+
# imgplot = plt.imshow(W[:,i].reshape(28, 28), cmap='gray')
29+
# plt.show()
30+
# should_quit = raw_input("Show more? Enter 'n' to quit\n")
31+
# if should_quit == 'n':
32+
# break
33+
34+
# TODO: save the weights so I can initialize from them later
35+
# and just do the last step
36+
37+
# print features learned in the last layer
38+
for k in xrange(dbn.hidden_layers[-1].M):
39+
# activate the kth node
40+
X = dbn.fit_to_input(k)
41+
imgplot = plt.imshow(X.reshape(28, 28), cmap='gray')
42+
plt.show()
43+
should_quit = raw_input("Show more? Enter 'n' to quit\n")
44+
if should_quit == 'n':
45+
break
46+
47+
48+
if __name__ == '__main__':
49+
main()

0 commit comments

Comments
 (0)