GeezerVison is showing github.com — add inputs the classifer · mpage/DeepLearningTutorials@373dfbf
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: code/logistic_sgd.py +5-9Lines changed: 5 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
44 | 44 |
|
45 | 45 | import theano |
46 | 46 | import theano.tensor as T |
47 | | -from theano.gof import graph |
48 | 47 |
|
49 | 48 |
|
50 | 49 | class LogisticRegression(object): |
@@ -110,6 +109,9 @@ def __init__(self, input, n_in, n_out): |
110 | 109 | # parameters of the model |
111 | 110 | self.params = [self.W, self.b] |
112 | 111 |
|
| 112 | + # keep track of model input |
| 113 | + self.input = input |
| 114 | + |
113 | 115 | def negative_log_likelihood(self, y): |
114 | 116 | """Return the mean of the negative log-likelihood of the prediction |
115 | 117 | of this model under a given target distribution. |
@@ -447,17 +449,11 @@ def predict(): |
447 | 449 |
|
448 | 450 | # load the saved model |
449 | 451 | classifier = cPickle.load(open('best_model.pkl')) |
450 | | - y_pred = classifier.y_pred |
451 | | - |
452 | | - # find the input to theano graph |
453 | | - inputs = graph.inputs([y_pred]) |
454 | | - # select only x |
455 | | - inputs = [item for item in inputs if item.name == 'x'] |
456 | 452 |
|
457 | 453 | # compile a predictor function |
458 | 454 | predict_model = theano.function( |
459 | | - inputs=inputs, |
460 | | - outputs=y_pred) |
| 455 | + inputs=[classifier.input], |
| 456 | + outputs=classifier.y_pred) |
461 | 457 |
|
462 | 458 | # We can test it on some examples from test test |
463 | 459 | dataset='mnist.pkl.gz' |
|
Collapse file
Copy file name to clipboardExpand all lines: doc/logreg.txt +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -274,8 +274,7 @@ labels of new data. ``predict`` function shows an example of how |
274 | 274 | this could be done. |
275 | 275 |
|
276 | 276 | .. literalinclude:: ../code/logistic_sgd.py |
277 | | - :start-after: ' ran for %.1fs' % ((end_time - start_time))) |
278 | | - :end-before: if __name__ == '__main__': |
| 277 | + :pyobject: predict |
279 | 278 |
|
280 | 279 |
|
281 | 280 | .. rubric:: Footnotes |
|