I am also using the same code for saving my trained network and predict on my new dataset. The code I am using is https://github.com/aseveryn/deep-qa. The main part is run_nnet.py. I could save and load my network by the same code in https://github.com/lzhbrian/RBM-DBN-theano-DL4J/blob/master/src/theano/code/logistic_sgd.py . but I continously get the same errors in this part,
predict_model = theano.function(inputs=[classifier.input], outputs=classifier.y_pred) actually I am not certain what I need to put in the inputs according to my code. Which one is right? inputs=[main.predict_prob_batch.batch_iterator], outputs=test_nnet.layers[-1].y_pred) inputs=[predict_prob_batch.batch_iterator], outputs=test_nnet.layers[-1].y_pred) inputs=[MiniBatchIteratorConstantBatchSize.dataset], outputs=test_nnet.layers[-1].y_pred) each of them I try I got the errors: ImportError: No module named MiniBatchIteratorConstantBatchSize or NameError: global name 'predict_prob_batch' is not defined I would really appreciate if you could help me. I also used this command for running the code but still the errors. python -c 'from run_nnet import predict; from sgd_trainer import MiniBatchIteratorConstantBatchSize; from MiniBatchIteratorConstantBatchSize import dataset; print predict()' python -c 'from run_nnet import predict; from sgd_trainer import *; from MiniBatchIteratorConstantBatchSize import dataset; print predict()' Thank you. On Friday, September 11, 2015 at 12:19:20 PM UTC-4, Lazaros Polymenakos wrote: > > Thank you very much Daniel. The test commands you posted below, helped me > trace the problem(s) > > For the record: there were several problems that had to be fixed: > > 1) in copying the logistic_sgd and modifying it to run on my data, the > line > > self.input = input > > was commented out. > > 2) The pickle file was never saved properly because of the above. > > 3) when running the predict() function from a python command line, > importing just the file that contains it (in this case logistic_sgd) did > not seem to be enough. When I finally did: from logistic_reg import * > (with the above problems fixed) it worked! > > Many thanks for the help, > > LP > > > > On Thursday, September 10, 2015 at 7:45:23 AM UTC-4, Daniel Renshaw wrote: >> >> The LogisticRegression class in the Theano sample definitely has an >> attribute called `ìnput`. Have you created your own class called >> LogisticRegression that is could be conflicting with the sample code's >> version? >> >> To help test this, what happens if you run the following code while in >> the current directory of wherever you have saved the logistic_sgd.py script? >> >> import theano >> import theano.tensor as tt >> import logistic_sgd >> a = logistic_sgd.LogisticRegression(tt.matrix(name='x'), 10, 20) >> print a.input.name >> >> This should not cause any errors and should simply print `x`. >> >> Daniel >> >> >> On 9 September 2015 at 16:46, Lazaros Polymenakos <l.poly...@gmail.com> >> wrote: >> >>> Hello Daniel, >>> >>> The classifier2 is a typo that I introduced when I tranferred the code >>> to post it. >>> >>> it should read classifier.input. >>> >>> >>> Here is what the error is pasted again: >>> >>> logistic_reg.predict() >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in <module> >>> File "logistic_reg.py", line 180, in predict >>> inputs=[classifier.input], >>> AttributeError: 'LogisticRegression' object has no attribute 'input' >>> >>> >>> Sorry about the confusion. >>> >>> Many thanks. >>> >>> LP >>> >>> >>> On Tuesday, September 8, 2015 at 8:52:38 PM UTC-4, Lazaros Polymenakos >>> wrote: >>>> >>>> Hello, >>>> >>>> I am fairly new to THEANO. I am trying out the examples and adapting >>>> them to run new experiments. >>>> >>>> In the documentation, there is a piece of code for the Logistic >>>> Regression example that is called predict() >>>> and it is used to load a trained model and test on a set of data. >>>> >>>> I append the modified code. The actual data loads and the sizes are >>>> correct. >>>> >>>> I get the following error: >>>> >>>> Traceback (most recent call last): >>>> File "<stdin>", line 1, in <module> >>>> File "logistic_reg.py", line 180, in predict >>>> inputs=[classifier.input], >>>> AttributeError: 'LogisticRegression' object has no attribute 'input' >>>> >>>> >>>> I would appreciate some insight on what could be wrong and how I could >>>> fix it. >>>> >>>> >>>> def predict(): >>>> """ >>>> An example of how to load a trained model and use it >>>> to predict labels. >>>> """ >>>> >>>> # load the saved model >>>> classifier = cPickle.load(open('best_model.pkl')) >>>> print classifier.b.get_value().shape >>>> # compile a predictor function >>>> predict_model = theano.function( >>>> inputs=[classifier.input], >>>> outputs=classifier.y_pred) >>>> >>>> # We can test it on some examples from test test >>>> # dataset='mnist.pkl.gz' >>>> # datasets = load_data(dataset) >>>> # test_set_x, test_set_y = datasets[2] >>>> # test_set_x = test_set_x.get_value() >>>> train_set_x = numpy.load('m_trainA.npy') >>>> train_set_y = numpy.load('m_labels1.npy') >>>> test_set_x = numpy.load('m_testA.npy') >>>> test_set_y = numpy.load('m_labels2.npy') >>>> >>>> predicted_values = predict_model(test_set_x[:10]) >>>> print ("Predicted values for the first 10 examples in test set:") >>>> print predicted_values >>>> >>>> Many thanks in advance >>>> >>>> -- >>> >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "theano-users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to theano-users...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.