MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / main

Function main

unsupervised_class2/visualize_features.py:20–51  ·  view source on GitHub ↗
(loadfile=None, savefile=None)

Source from the content-addressed store, hash-verified

18
19
20def main(loadfile=None, savefile=None):
21 Xtrain, Ytrain, Xtest, Ytest = getKaggleMNIST()
22 if loadfile:
23 dbn = DBN.load(loadfile)
24 else:
25 dbn = DBN([1000, 750, 500, 10]) # AutoEncoder is default
26 # dbn = DBN([1000, 750, 500, 10], UnsupervisedModel=RBM)
27 dbn.fit(Xtrain, pretrain_epochs=2)
28
29 if savefile:
30 dbn.save(savefile)
31
32 # first layer features
33 # initial weight is D x M
34 W = dbn.hidden_layers[0].W.eval()
35 for i in range(dbn.hidden_layers[0].M):
36 imgplot = plt.imshow(W[:,i].reshape(28, 28), cmap='gray')
37 plt.show()
38 should_quit = input("Show more? Enter 'n' to quit\n")
39 if should_quit == 'n':
40 break
41
42 # features learned in the last layer
43 for k in range(dbn.hidden_layers[-1].M):
44 # activate the kth node
45 X = dbn.fit_to_input(k)
46 imgplot = plt.imshow(X.reshape(28, 28), cmap='gray')
47 plt.show()
48 if k < dbn.hidden_layers[-1].M - 1:
49 should_quit = input("Show more? Enter 'n' to quit\n")
50 if should_quit == 'n':
51 break
52
53
54if __name__ == '__main__':

Callers 1

Calls 6

fitMethod · 0.95
saveMethod · 0.95
fit_to_inputMethod · 0.95
getKaggleMNISTFunction · 0.90
DBNClass · 0.90
loadMethod · 0.45

Tested by

no test coverage detected